[SOLVED] static/class method in micropython?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

[SOLVED] static/class method in micropython?

Post by shawwwn » Tue Sep 11, 2018 6:31 am

Judging from the source, currently class method in micropython is not supported.
The underlying C struct of mp class instance only has .locals_dict.

Any plans to add support for class or static method?
This feature would be really useful for module developers.

Thanks.
Last edited by shawwwn on Tue Sep 11, 2018 8:14 am, edited 2 times in total.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: static/class method in micropython?

Post by stijn » Tue Sep 11, 2018 6:51 am

Actually class methods (assuming you mean methods inside a class decorated with @classmethod) are supported. Look at the mp_type_classmethod type.

shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

Re: static/class method in micropython?

Post by shawwwn » Tue Sep 11, 2018 7:44 am

Nice. Thanks for pointing that out.

I am finding a way to implement static method in a python class written in C.
Any ideas how it can be done?

shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

Re: static/class method in micropython?

Post by shawwwn » Tue Sep 11, 2018 8:13 am

Nvm. I found it.

Inside py/obj.h,
there is a macro called

Code: Select all

MP_DEFINE_CONST_STATICMETHOD_OBJ
which puts a staticmethod wrap onto a function.

Thanks for the help!
I'm closing this issue.

Post Reply