Skip to content

Commit 7516332

Browse files
committed
tests/cpydiff: Add cases for locals() discrepancies.
MicroPython doesn't maintain local symbolic environment, so any feature depending on it won't work as expected.
1 parent 280fb4d commit 7516332

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tests/cpydiff/core_locals.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
categories: Core,Runtime
3+
description: Local variables aren't included in locals() result
4+
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name.
5+
workaround: Unknown
6+
"""
7+
def test():
8+
val = 2
9+
print(locals())
10+
11+
test()

tests/cpydiff/core_locals_eval.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
categories: Core,Runtime
3+
description: Code running in eval() function doesn't have access to local variables
4+
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
5+
workaround: Unknown
6+
"""
7+
val = 1
8+
9+
def test():
10+
val = 2
11+
print(val)
12+
eval("print(val)")
13+
14+
test()

0 commit comments

Comments
 (0)