summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/annotate_var.py
diff options
context:
space:
mode:
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()