summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/annotate_var.py
blob: a359b229b1a951da461f55c5147c8ff3c46cc6e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# test PEP 526, variable 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()