summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/annotate_var.py
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/basics/annotate_var.py
parentf2e267da68bf85f3f12fa77155e469352bdc6c09 (diff)
downloadmicropython-a51eef4471e01ee60d53ee184bc4feabf6ebd855.tar.gz
micropython-a51eef4471e01ee60d53ee184bc4feabf6ebd855.zip
tests/basics: Add tests for variable annotations.
Diffstat (limited to 'tests/basics/annotate_var.py')
-rw-r--r--tests/basics/annotate_var.py25
1 files changed, 25 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()