diff options
author | Damien George <damien@micropython.org> | 2020-06-21 17:25:44 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-06-24 12:05:40 +1000 |
commit | 457fdf61c3bca550b4ad3fb2c6822c838984dac0 (patch) | |
tree | 82b9b90208d1aabe81840392ac11ea560b8f11d8 /tests | |
parent | 7dd480ad5505a40bb33ee52d01c5fa78b1273083 (diff) | |
download | micropython-457fdf61c3bca550b4ad3fb2c6822c838984dac0.tar.gz micropython-457fdf61c3bca550b4ad3fb2c6822c838984dac0.zip |
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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/class_ordereddict.py | 18 | ||||
-rw-r--r-- | tests/basics/class_ordereddict.py.exp | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/tests/basics/class_ordereddict.py b/tests/basics/class_ordereddict.py new file mode 100644 index 0000000000..4dd25eb6e1 --- /dev/null +++ b/tests/basics/class_ordereddict.py @@ -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("_")]) diff --git a/tests/basics/class_ordereddict.py.exp b/tests/basics/class_ordereddict.py.exp new file mode 100644 index 0000000000..b723e32751 --- /dev/null +++ b/tests/basics/class_ordereddict.py.exp @@ -0,0 +1 @@ +['a', 'b', 'c', 'd', 'e'] |