Setting attributes of parent class from child class __init__ issue (external C module) #13109
-
Hi, I have the following simple external C module class object that I am building in MicroPython 1.19.1:
The above will get exposed through some module. The problem I am having is with not being able to set attributes of the parent in a child class as seen below:
Now the problem above is that when setting the width and height the print statement in Being able to have the values stored in an direct access sort of way in C is much better than needing to do a Any help is appreciated. Please let me know if you need more information. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@jmtinycircuits Unfortunately for optimisation/space reasons there are several limitations placed on inheritance from built-in types. This stems from the fact that inheritance from built-in (native) types works differently to inheritance from instance types. The main thing to be aware of is that a type's
(when the store to Unfortunately I don't see a way to (ab)use this mechanism to achieve what you want. I think the |
Beta Was this translation helpful? Give feedback.
@jmtinycircuits Unfortunately for optimisation/space reasons there are several limitations placed on inheritance from built-in types. This stems from the fact that inheritance from built-in (native) types works differently to inheritance from instance types.
The main thing to be aware of is that a type's
attr
handler is not equivalent to Python's__setattr__
(i.e. it's not polymorphic). Which is why this works in Python (and MicroPython):(when the store to
d.foo
is resolved, it sees Derived as having a__setattr__
method)Unfortunately I don't see a…