tests/basics: Add tests for variable annotations.

pull/6126/head
Damien George 2020-06-16 22:49:38 +10:00
rodzic f2e267da68
commit a51eef4471
3 zmienionych plików z 31 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,25 @@
# test PEP 526, varible annotations
x: int
print("x" in globals())
x: int = 1
print(x)
t: tuple = 1, 2
print(t)
# a pure annotation in a function makes that variable local
def f():
x: int
try:
print(x)
except NameError:
print("NameError")
f()
# here, "x" should remain a global
def f():
x.y: int
print(x)
f()

Wyświetl plik

@ -0,0 +1,5 @@
False
1
(1, 2)
NameError
1

Wyświetl plik

@ -414,6 +414,7 @@ def run_tests(pyb, tests, args, base_path="."):
skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from_close generator_name'.split()}) # require raise_varargs, generator name
skip_tests.update({'basics/async_%s.py' % t for t in 'with with2 with_break with_return'.split()}) # require async_with
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs
skip_tests.add('basics/annotate_var.py') # requires checking for unbound local
skip_tests.add('basics/del_deref.py') # requires checking for unbound local
skip_tests.add('basics/del_local.py') # requires checking for unbound local
skip_tests.add('basics/exception_chain.py') # raise from is not supported