8000 tests/basics: Add tests for variable annotations. · micropython/micropython@ceffb08 · GitHub
[go: up one dir, main page]

Skip to content

Commit ceffb08

Browse files
committed
tests/basics: Add tests for variable annotations.
1 parent fe37667 commit ceffb08

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

tests/basics/annotate_var.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# test PEP 526, varible annotations
2+
3+
x: int
4+
print("x" in globals())
5+
6+
x: int = 1
7+
print(x)
8+
9+
t: tuple = 1, 2
10+
print(t)
11+
12+
# a pure annotation in a function makes that variable local
13+
def f():
14+
x: int
15+
try:
16+
print(x)
17+
except NameError:
18+
print("NameError")
19+
f()
20+
21+
# here, "x" should remain a global
22+
def f():
23+
x.y: int
24+
print(x)
25+
f()

tests/basics/annotate_var.py.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
False
2+
1
3+
(1, 2)
4+
NameError
5+
1

tests/run-tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def run_tests(pyb, tests, args, base_path="."):
414414
skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from_close generator_name'.split()}) # require raise_varargs, generator name
415415
skip_tests.update({'basics/async_%s.py' % t for t in 'with with2 with_break with_return'.split()}) # require async_with
416416
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs
417+
skip_tests.add('basics/annotate_var.py') # requires checking for unbound local
417418
skip_tests.add('basics/del_deref.py') # requires checking for unbound local
418419
skip_tests.add('basics/del_local.py') # requires checking for unbound local
419420
skip_tests.add('basics/exception_chain.py') # raise from is not supported

0 commit comments

Comments
 (0)
0