summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-06-16 22:49:38 +1000
committerDamien George <damien@micropython.org>2020-06-16 23:18:01 +1000
commita51eef4471e01ee60d53ee184bc4feabf6ebd855 (patch)
tree6f257b242f5ff39828239e1421b7d07e92fcf185 /tests
parentf2e267da68bf85f3f12fa77155e469352bdc6c09 (diff)
downloadmicropython-a51eef4471e01ee60d53ee184bc4feabf6ebd855.tar.gz
micropython-a51eef4471e01ee60d53ee184bc4feabf6ebd855.zip
tests/basics: Add tests for variable annotations.
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/annotate_var.py25
-rw-r--r--tests/basics/annotate_var.py.exp5
-rwxr-xr-xtests/run-tests1
3 files changed, 31 insertions, 0 deletions
diff --git a/tests/basics/annotate_var.py b/tests/basics/annotate_var.py
new file mode 100644
index 0000000000..3f767e4a73
--- /dev/null
+++ b/tests/basics/annotate_var.py
@@ -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()
diff --git a/tests/basics/annotate_var.py.exp b/tests/basics/annotate_var.py.exp
new file mode 100644
index 0000000000..9b6536e966
--- /dev/null
+++ b/tests/basics/annotate_var.py.exp
@@ -0,0 +1,5 @@
+False
+1
+(1, 2)
+NameError
+1
diff --git a/tests/run-tests b/tests/run-tests
index 74e2f71ac6..f9e4de4b34 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -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