Page 1 of 1

Subclassing native classes

Posted: Fri Jan 04, 2019 8:58 pm
by agonnen
I would like to know what is the status of Subclassing native classes in Micropython.
Specifically, I have a C library which I expose in Micropython, and would like to subclass its objects in Micropython.
The official docs only mention that "Subclassing native classes is not fully supported in MicroPython" (https://micropython.org/resources/docs/ ... types.html).

Does anyone know what is actually supported and what is not when subclassing a native type or classes from a user added module?

Re: Subclassing native classes

Posted: Mon Jan 14, 2019 11:21 am
by Maksym Galemin
As per the Exception.__init__ method does not exist. item I think the limitation is that you should use super().__init__() instead of BaseNativeClass.__init__() in constructors of your subclasses derived from native classes. And I guess you should check native_base_init_wrapper() function from py/objtype.c for details (or just search for "native_base" in this file and check the code). But I might be wrong... :)

In any case it would be better if you could include an example of your subclasses derived from native uPy classes as it's much easier to deal with some specific cases rather than describing all possible scenarios.

Re: Subclassing native classes

Posted: Mon Jan 14, 2019 8:01 pm
by pfalcon