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()
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$
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