Subclassing native classes

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
agonnen
Posts: 7
Joined: Sat Oct 13, 2018 7:52 pm

Subclassing native classes

Post by agonnen » Fri Jan 04, 2019 8:58 pm

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?

Maksym Galemin
Posts: 10
Joined: Mon May 28, 2018 11:48 pm

Re: Subclassing native classes

Post by Maksym Galemin » Mon Jan 14, 2019 11:21 am

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.

pfalcon
Posts: 1125
Joined: Fri Feb 28, 2014 2:05 pm

Re: Subclassing native classes

Post by pfalcon » Mon Jan 14, 2019 8:01 pm

Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply