summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/class_dict.py
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2020-06-10 10:45:24 +1000
committerDamien George <damien.p.george@gmail.com>2020-06-10 21:58:13 +1000
commit28370c04509a6255cd3d6b9424443a5b57bb7467 (patch)
tree98d1f78a1805d14b85a88e54c910e0cf46168598 /tests/basics/class_dict.py
parent29e258611ace8e4de51d810d5ff14364a5fbb950 (diff)
downloadmicropython-28370c04509a6255cd3d6b9424443a5b57bb7467.tar.gz
micropython-28370c04509a6255cd3d6b9424443a5b57bb7467.zip
py/objtype: Add __dict__ attribute for class objects.
The behavior mirrors the instance object dict attribute where a copy of the local attributes are provided (unless the dict is read-only, then that dict itself is returned, as an optimisation). MicroPython does not support modifying this dict because the changes will not be reflected in the class. The feature is only enabled if MICROPY_CPYTHON_COMPAT is set, the same as the instance version.
Diffstat (limited to 'tests/basics/class_dict.py')
-rw-r--r--tests/basics/class_dict.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/basics/class_dict.py b/tests/basics/class_dict.py
new file mode 100644
index 0000000000..f80ded678b
--- /dev/null
+++ b/tests/basics/class_dict.py
@@ -0,0 +1,19 @@
+# test __dict__ attribute of a class
+
+if not hasattr(int, "__dict__"):
+ print("SKIP")
+ raise SystemExit
+
+
+# dict of a built-in type
+print("from_bytes" in int.__dict__)
+
+
+# dict of a user class
+class Foo:
+ a = 1
+ b = "bar"
+
+
+d = Foo.__dict__
+print(d["a"], d["b"])