13
13
from test import support
14
14
15
15
def to_tuple (t ):
16
- if t is None or isinstance (t , (str , int , complex )):
16
+ if t is None or isinstance (t , (str , int , complex )) or t is Ellipsis :
17
17
return t
18
18
elif isinstance (t , list ):
19
19
return [to_tuple (e ) for e in t ]
@@ -46,10 +46,20 @@ def to_tuple(t):
46
46
"def f(a=0): pass" ,
47
47
# FunctionDef with varargs
48
48
"def f(*args): pass" ,
49
+ # FunctionDef with varargs as TypeVarTuple
50
+ "def f(*args: *Ts): pass" ,
51
+ # FunctionDef with varargs as unpacked Tuple
52
+ "def f(*args: *tuple[int, ...]): pass" ,
53
+ # FunctionDef with varargs as unpacked Tuple *and* TypeVarTuple
54
+ "def f(*args: *tuple[int, *Ts]): pass" ,
49
55
# FunctionDef with kwargs
50
56
"def f(**kwargs): pass" ,
51
57
# FunctionDef with all kind of args and docstring
52
58
"def f(a, b=1, c=None, d=[], e={}, *args, f=42, **kwargs): 'doc for f()'" ,
59
+ # FunctionDef with type annotation on return involving unpacking
60
+ "def f() -> tuple[*Ts]: pass" ,
61
+ "def f() -> tuple[int, *Ts]: pass" ,
62
+ "def f() -> tuple[int, *tuple[int, ...]]: pass" ,
53
63
# ClassDef
54
64
"class C:pass" ,
55
65
# ClassDef with docstring
@@ -65,6 +75,10 @@ def to_tuple(t):
65
75
"a,b = c" ,
66
76
"(a,b) = c" ,
67
77
"[a,b] = c" ,
78
+ # AnnAssign with unpacked types
79
+ "x: tuple[*Ts]" ,
80
+ "x: tuple[int, *Ts]" ,
81
+ "x: tuple[int, *tuple[str, ...]]" ,
68
82
# AugAssign
69
83
"v += 1" ,
70
84
# For
@@ -2315,8 +2329,14 @@ def main():
2315
2329
('Module' , [('FunctionDef' , (1 , 0 , 1 , 14 ), 'f' , ('arguments' , [], [('arg' , (1 , 6 , 1 , 7 ), 'a' , None , None )], None , [], [], None , []), [('Pass' , (1 , 10 , 1 , 14 ))], [], None , None )], []),
2316
2330
('Module' , [('FunctionDef' , (1 , 0 , 1 , 16 ), 'f' , ('arguments' , [], [('arg' , (1 , 6 , 1 , 7 ), 'a' , None , None )], None , [], [], None , [('Constant' , (1 , 8 , 1 , 9 ), 0 , None )]), [('Pass' , (1 , 12 , 1 , 16 ))], [], None , None )], []),
2317
2331
('Module' , [('FunctionDef' , (1 , 0 , 1 , 18 ), 'f' , ('arguments' , [], [], ('arg' , (1 , 7 , 1 , 11 ), 'args' , None , None ), [], [], None , []), [('Pass' , (1 , 14 , 1 , 18 ))], [], None , None )], []),
2332
+ ('Module' , [('FunctionDef' , (1 , 0 , 1 , 23 ), 'f' , ('arguments' , [], [], ('arg' , (1 , 7 , 1 , 16 ), 'args' , ('Starred' , (1 , 13 , 1 , 16 ), ('Name' , (1 , 14 , 1 , 16 ), 'Ts' , ('Load' ,)), ('Load' ,)), None ), [], [], None , []), [('Pass' , (1 , 19 , 1 , 23 ))], [], None , None )], []),
2333
+ ('Module' , [('FunctionDef' , (1 , 0 , 1 , 36 ), 'f' , ('arguments' , [], [], ('arg' , (1 , 7 , 1 , 29 ), 'args' , ('Starred' , (1 , 13 , 1 , 29 ), ('Subscript' , (1 , 14 , 1 , 29 ), ('Name' , (1 , 14 , 1 , 19 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 20 , 1 , 28 ), [('Name' , (1 , 20 , 1 , 23 ), 'int' , ('Load' ,)), ('Constant' , (1 , 25 , 1 , 28 ), Ellipsis , None )], ('Load' ,)), ('Load' ,)), ('Load' ,)), None ), [], [], None , []), [('Pass' , (1 , 32 , 1 , 36 ))], [], None , None )], []),
2334
+ ('Module' , [('FunctionDef' , (1 , 0 , 1 , 36 ), 'f' , ('arguments' , [], [], ('arg' , (1 , 7 , 1 , 29 ), 'args' , ('Starred' , (1 , 13 , 1 , 29 ), ('Subscript' , (1 , 14 , 1 , 29 ), ('Name' , (1 , 14 , 1 , 19 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 20 , 1 , 28 ), [('Name' , (1 , 20 , 1 , 23 ), 'int' , ('Load' ,)), ('Starred' , (1 , 25 , 1 , 28 ), ('Name' , (1 , 26 , 1 , 28 ), 'Ts' , ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), ('Load' ,)), None ), [], [], None , []), [('Pass' , (1 , 32 , 1 , 36 ))], [], None , None )], []),
2318
2335
('Module' , [('FunctionDef' , (1 , 0 , 1 , 21 ), 'f' , ('arguments' , [], [], None , [], [], ('arg' , (1 , 8 , 1 , 14 ), 'kwargs' , None , None ), []), [('Pass' , (1 , 17 , 1 , 21 ))], [], None , None )], []),
2319
2336
('Module' , [('FunctionDef' , (1 , 0 , 1 , 71 ), 'f' , ('arguments' , [], [('arg' , (1 , 6 , 1 , 7 ), 'a' , None , None ), ('arg' , (1 , 9 , 1 , 10 ), 'b' , None , None ), ('arg' , (1 , 14 , 1 , 15 ), 'c' , None , None ), ('arg' , (1 , 22 , 1 , 23 ), 'd' , None , None ), ('arg' , (1 , 28 , 1 , 29 ), 'e' , None , None )], ('arg' , (1 , 35 , 1 , 39 ), 'args' , None , None ), [('arg' , (1 , 41 , 1 , 42 ), 'f' , None , None )], [('Constant' , (1 , 43 , 1 , 45 ), 42 , None )], ('arg' , (1 , 49 , 1 , 55 ), 'kwargs' , None , None ), [('Constant' , (1 , 11 , 1 , 12 ), 1 , None ), ('Constant' , (1 , 16 , 1 , 20 ), None , None ), ('List' , (1 , 24 , 1 , 26 ), [], ('Load' ,)), ('Dict' , (1 , 30 , 1 , 32 ), [], [])]), [('Expr' , (1 , 58 , 1 , 71 ), ('Constant' , (1 , 58 , 1 , 71 ), 'doc for f()' , None ))], [], None , None )], []),
2337
+ ('Module' , [('FunctionDef' , (1 , 0 , 1 , 27 ), 'f' , ('arguments' , [], [], None , [], [], None , []), [('Pass' , (1 , 23 , 1 , 27 ))], [], ('Subscript' , (1 , 11 , 1 , 21 ), ('Name' , (1 , 11 , 1 , 16 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 17 , 1 , 20 ), [('Starred' , (1 , 17 , 1 , 20 ), ('Name' , (1 , 18 , 1 , 20 ), 'Ts' , ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), None )], []),
2338
+ ('Module' , [('FunctionDef' , (1 , 0 , 1 , 32 ), 'f' , ('arguments' , [], [], None , [], [], None , []), [('Pass' , (1 , 28 , 1 , 32 ))], [], ('Subscript' , (1 , 11 , 1 , 26 ), ('Name' , (1 , 11 , 1 , 16 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 17 , 1 , 25 ), [('Name' , (1 , 17 , 1 , 20 ), 'int' , ('Load' ,)), ('Starred' , (1 , 22 , 1 , 25 ), ('Name' , (1 , 23 , 1 , 25 ), 'Ts' , ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), None )], []),
2339
+ ('Module' , [('FunctionDef' , (1 , 0 , 1 , 45 ), 'f' , ('arguments' , [], [], None , [], [], None , []), [('Pass' , (1 , 41 , 1 , 45 ))], [], ('Subscript' , (1 , 11 , 1 , 39 ), ('Name' , (1 , 11 , 1 , 16 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 17 , 1 , 38 ), [('Name' , (1 , 17 , 1 , 20 ), 'int' , ('Load' ,)), ('Starred' , (1 , 22 , 1 , 38 ), ('Subscript' , (1 , 23 , 1 , 38 ), ('Name' , (1 , 23 , 1 , 28 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 29 , 1 , 37 ), [('Name' , (1 , 29 , 1 , 32 ), 'int' , ('Load' ,)), ('Constant' , (1 , 34 , 1 , 37 ), Ellipsis , None )], ('Load' ,)), ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), None )], []),
2320
2340
('Module' , [('ClassDef' , (1 , 0 , 1 , 12 ), 'C' , [], [], [('Pass' , (1 , 8 , 1 , 12 ))], [])], []),
2321
2341
('Module' , [('ClassDef' , (1 , 0 , 1 , 32 ), 'C' , [], [], [('Expr' , (1 , 9 , 1 , 32 ), ('Constant' , (1 , 9 , 1 , 32 ), 'docstring for class C' , None ))], [])], []),
2322
2342
('Module' , [('ClassDef' , (1 , 0 , 1 , 21 ), 'C' , [('Name' , (1 , 8 , 1 , 14 ), 'object' , ('Load' ,))], [], [('Pass' , (1 , 17 , 1 , 21 ))], [])], []),
@@ -2326,6 +2346,9 @@ def main():
2326
2346
('Module' , [('Assign' , (1 , 0 , 1 , 7 ), [('Tuple' , (1 , 0 , 1 , 3 ), [('Name' , (1 , 0 , 1 , 1 ), 'a' , ('Store' ,)), ('Name' , (1 , 2 , 1 , 3 ), 'b' , ('Store' ,))], ('Store' ,))], ('Name' , (1 , 6 , 1 , 7 ), 'c' , ('Load' ,)), None )], []),
2327
2347
('Module' , [('Assign' , (1 , 0 , 1 , 9 ), [('Tuple' , (1 , 0 , 1 , 5 ), [('Name' , (1 , 1 , 1 , 2 ), 'a' , ('Store' ,)), ('Name' , (1 , 3 , 1 , 4 ), 'b' , ('Store' ,))], ('Store' ,))], ('Name' , (1 , 8 , 1 , 9 ), 'c' , ('Load' ,)), None )], []),
2328
2348
('Module' , [('Assign' , (1 , 0 , 1 , 9 ), [('List' , (1 , 0 , 1 , 5 ), [('Name' , (1 , 1 , 1 , 2 ), 'a' , ('Store' ,)), ('Name' , (1 , 3 , 1 , 4 ), 'b' , ('Store' ,))], ('Store' ,))], ('Name' , (1 , 8 , 1 , 9 ), 'c' , ('Load' ,)), None )], []),
2349
+ ('Module' , [('AnnAssign' , (1 , 0 , 1 , 13 ), ('Name' , (1 , 0 , 1 , 1 ), 'x' , ('Store' ,)), ('Subscript' , (1 , 3 , 1 , 13 ), ('Name' , (1 , 3 , 1 , 8 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 9 , 1 , 12 ), [('Starred' , (1 , 9 , 1 , 12 ), ('Name' , (1 , 10 , 1 , 12 ), 'Ts' , ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), None , 1 )], []),
2350
+ ('Module' , [('AnnAssign' , (1 , 0 , 1 , 18 ), ('Name' , (1 , 0 , 1 , 1 ), 'x' , ('Store' ,)), ('Subscript' , (1 , 3 , 1 , 18 ), ('Name' , (1 , 3 , 1 , 8 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 9 , 1 , 17 ), [('Name' , (1 , 9 , 1 , 12 ), 'int' , ('Load' ,)), ('Starred' , (1 , 14 , 1 , 17 ), ('Name' , (1 , 15 , 1 , 17 ), 'Ts' , ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), None , 1 )], []),
2351
+ ('Module' , [('AnnAssign' , (1 , 0 , 1 , 31 ), ('Name' , (1 , 0 , 1 , 1 ), 'x' , ('Store' ,)), ('Subscript' , (1 , 3 , 1 , 31 ), ('Name' , (1 , 3 , 1 , 8 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 9 , 1 , 30 ), [('Name' , (1 , 9 , 1 , 12 ), 'int' , ('Load' ,)), ('Starred' , (1 , 14 , 1 , 30 ), ('Subscript' , (1 , 15 , 1 , 30 ), ('Name' , (1 , 15 , 1 , 20 ), 'tuple' , ('Load' ,)), ('Tuple' , (1 , 21 , 1 , 29 ), [('Name' , (1 , 21 , 1 , 24 ), 'str' , ('Load' ,)), ('Constant' , (1 , 26 , 1 , 29 ), Ellipsis , None )], ('Load' ,)), ('Load' ,)), ('Load' ,))], ('Load' ,)), ('Load' ,)), None , 1 )], []),
2329
2352
('Module' , [('AugAssign' , (1 , 0 , 1 , 6 ), ('Name' , (1 , 0 , 1 , 1 ), 'v' , ('Store' ,)), ('Add' ,), ('Constant' , (1 , 5 , 1 , 6 ), 1 , None ))], []),
2330
2353
('Module' , [('For' , (1 , 0 , 1 , 15 ), ('Name' , (1 , 4 , 1 , 5 ), 'v' , ('Store' ,)), ('Name' , (1 , 9 , 1 , 10 ), 'v' , ('Load' ,)), [('Pass' , (1 , 11 , 1 , 15 ))], [], None )], []),
2331
2354
('Module' , [('While' , (1 , 0 , 1 , 12 ), ('Name' , (1 , 6 , 1 , 7 ), 'v' , ('Load' ,)), [('Pass' , (1 , 8 , 1 , 12 ))], [])], []),
0 commit comments