mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
py/objtype: Support passing in an OrderedDict to type() as the locals.
An OrderedDict can now be used for the locals when creating a type explicitly via type(name, bases, locals). Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
18
tests/basics/class_ordereddict.py
Normal file
18
tests/basics/class_ordereddict.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# test using an OrderedDict as the locals to construct a class
|
||||
|
||||
try:
|
||||
from ucollections import OrderedDict
|
||||
except ImportError:
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
if not hasattr(int, "__dict__"):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
A = type("A", (), OrderedDict(a=1, b=2, c=3, d=4, e=5))
|
||||
print([k for k in A.__dict__.keys() if not k.startswith("_")])
|
||||
Reference in New Issue
Block a user