mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
py/objmodule: Add support for __dict__.
This matches class `__dict__`, and is similarly gated on MICROPY_CPYTHON_COMPAT. Unlike class though, because modules's globals are actually dict instances, the result is a mutable dictionary. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
d94141e147
commit
15d0615d5c
17
tests/import/module_dict.py
Normal file
17
tests/import/module_dict.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# test __dict__ attribute of a user module
|
||||
|
||||
import sys
|
||||
|
||||
if not hasattr(sys, "__dict__"):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
import import1b
|
||||
|
||||
# dict of a user module (read/write)
|
||||
print(import1b.var)
|
||||
print(import1b.__dict__["var"])
|
||||
import1b.__dict__["var"] = "hello"
|
||||
print(import1b.var)
|
||||
print(import1b.__dict__["var"])
|
||||
Reference in New Issue
Block a user