Metaclass support in Micropython

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
AndyFug
Posts: 9
Joined: Mon Jun 22, 2020 6:26 pm

Metaclass support in Micropython

Post by AndyFug » Wed Jul 01, 2020 9:59 am

Hi,

Are metaclasses supported in Micropython? I tried running the script below:

Code: Select all

class MetaTest(type):
    pass


class TestClass(metaclass=MetaTest):
    pass


if __name__ == "__main__":
    print(type(TestClass))
    print(type(MetaTest))

    a = TestClass()
and I was met with the following output on Micropython unix port:

Code: Select all

vagrant@ubuntu-bionic:~/micropython/ports/unix$ ./micropython ~/project/metatest.py
Traceback (most recent call last):
  File "/home/vagrant/project/metatest.py", line 5, in <module>
TypeError: function doesn't take keyword arguments
vagrant@ubuntu-bionic:~/micropython/ports/unix$
(Hoping my minimal test-case is relevant... I stripped it back to the bear minimum while replicating the same error I had with a more 'complete' metaclass)

This works fine on CPython, so I suspect it's a 'feature or fault' with Micropython. I am using a Micropython build from a few weeks' ago. If we think this is a bug rather than a limitation, I'll provide more details / submit an issue on GitHub.

If it's a 'feature'/by design, any work-arounds or other means for using metaclasses in Micropython would be great to know.

Cheers,

Andy

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Metaclass support in Micropython

Post by pythoncoder » Thu Jul 02, 2020 5:19 am

Peter Hinch
Index to my micropython libraries.

AndyFug
Posts: 9
Joined: Mon Jun 22, 2020 6:26 pm

Re: Metaclass support in Micropython

Post by AndyFug » Fri Jul 03, 2020 7:07 am

Thanks,
Ahh... I'll check that doc in future. Hadn't seen that.
Cheers, Andy

Post Reply