|
25 | 25 | ): |
26 | 26 | def foo(): ... |
27 | 27 | def invalid( |
28 | | - a_: a, # error: [invalid-type-form] "Variable of type `type[int]` is not allowed in a type expression" |
| 28 | + a_: a, # error: [invalid-type-form] "Variable of type `type[int]` is not allowed in a parameter annotation" |
29 | 29 | b_: b, # error: [invalid-type-form] |
30 | 30 | c_: c, # error: [invalid-type-form] |
31 | 31 | d_: d, # error: [invalid-type-form] |
|
35 | 35 | h_: h, # error: [invalid-type-form] |
36 | 36 | i_: typing, # error: [invalid-type-form] |
37 | 37 | j_: foo, # error: [invalid-type-form] |
38 | | - k_: i, # error: [invalid-type-form] "Variable of type `int` is not allowed in a type expression" |
39 | | - l_: j, # error: [invalid-type-form] "Variable of type `A` is not allowed in a type expression" |
| 38 | + k_: i, # error: [invalid-type-form] "Variable of type `int` is not allowed in a parameter annotation" |
| 39 | + l_: j, # error: [invalid-type-form] "Variable of type `A` is not allowed in a parameter annotation" |
40 | 40 | ): |
41 | 41 | reveal_type(a_) # revealed: Unknown |
42 | 42 | reveal_type(b_) # revealed: Unknown |
@@ -80,37 +80,37 @@ def bar() -> None: |
80 | 80 |
|
81 | 81 | def outer_sync(): # `yield` from is only valid syntax inside a synchronous function |
82 | 82 | def _( |
83 | | - a: (yield from [1]), # error: [invalid-type-form] "`yield from` expressions are not allowed in type expressions" |
| 83 | + a: (yield from [1]), # error: [invalid-type-form] "`yield from` expressions are not allowed in parameter annotations" |
84 | 84 | ): ... |
85 | 85 |
|
86 | 86 | async def baz(): ... |
87 | 87 | async def outer_async(): # avoid unrelated syntax errors on `yield` and `await` |
88 | 88 | def _( |
89 | | - a: 1, # error: [invalid-type-form] "Int literals are not allowed in this context in a type expression" |
90 | | - b: 2.3, # error: [invalid-type-form] "Float literals are not allowed in type expressions" |
91 | | - c: 4j, # error: [invalid-type-form] "Complex literals are not allowed in type expressions" |
92 | | - d: True, # error: [invalid-type-form] "Boolean literals are not allowed in this context in a type expression" |
| 89 | + a: 1, # error: [invalid-type-form] "Int literals are not allowed in this context in a parameter annotation" |
| 90 | + b: 2.3, # error: [invalid-type-form] "Float literals are not allowed in parameter annotations" |
| 91 | + c: 4j, # error: [invalid-type-form] "Complex literals are not allowed in parameter annotations" |
| 92 | + d: True, # error: [invalid-type-form] "Boolean literals are not allowed in this context in a parameter annotation" |
93 | 93 | # error: [unsupported-operator] |
94 | | - # error: [invalid-type-form] "Bytes literals are not allowed in this context in a type expression" |
| 94 | + # error: [invalid-type-form] "Bytes literals are not allowed in this context in a parameter annotation" |
95 | 95 | e: int | b"foo", |
96 | | - f: 1 and 2, # error: [invalid-type-form] "Boolean operations are not allowed in type expressions" |
97 | | - g: 1 or 2, # error: [invalid-type-form] "Boolean operations are not allowed in type expressions" |
98 | | - h: (foo := 1), # error: [invalid-type-form] "Named expressions are not allowed in type expressions" |
99 | | - i: not 1, # error: [invalid-type-form] "Unary operations are not allowed in type expressions" |
100 | | - j: lambda: 1, # error: [invalid-type-form] "`lambda` expressions are not allowed in type expressions" |
101 | | - k: 1 if True else 2, # error: [invalid-type-form] "`if` expressions are not allowed in type expressions" |
102 | | - l: await baz(), # error: [invalid-type-form] "`await` expressions are not allowed in type expressions" |
103 | | - m: (yield 1), # error: [invalid-type-form] "`yield` expressions are not allowed in type expressions" |
104 | | - n: 1 < 2, # error: [invalid-type-form] "Comparison expressions are not allowed in type expressions" |
105 | | - o: bar(), # error: [invalid-type-form] "Function calls are not allowed in type expressions" |
| 96 | + f: 1 and 2, # error: [invalid-type-form] "Boolean operations are not allowed in parameter annotations" |
| 97 | + g: 1 or 2, # error: [invalid-type-form] "Boolean operations are not allowed in parameter annotations" |
| 98 | + h: (foo := 1), # error: [invalid-type-form] "Named expressions are not allowed in parameter annotations" |
| 99 | + i: not 1, # error: [invalid-type-form] "Unary operations are not allowed in parameter annotations" |
| 100 | + j: lambda: 1, # error: [invalid-type-form] "`lambda` expressions are not allowed in parameter annotations" |
| 101 | + k: 1 if True else 2, # error: [invalid-type-form] "`if` expressions are not allowed in parameter annotations" |
| 102 | + l: await baz(), # error: [invalid-type-form] "`await` expressions are not allowed in parameter annotations" |
| 103 | + m: (yield 1), # error: [invalid-type-form] "`yield` expressions are not allowed in parameter annotations" |
| 104 | + n: 1 < 2, # error: [invalid-type-form] "Comparison expressions are not allowed in parameter annotations" |
| 105 | + o: bar(), # error: [invalid-type-form] "Function calls are not allowed in parameter annotations" |
106 | 106 | # error: [unsupported-operator] |
107 | | - # error: [invalid-type-form] "F-strings are not allowed in type expressions" |
| 107 | + # error: [invalid-type-form] "F-strings are not allowed in parameter annotations" |
108 | 108 | p: int | f"foo", |
109 | | - # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in type expressions" |
| 109 | + # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in parameter annotations" |
110 | 110 | q: [1, 2, 3][1:2], |
111 | | - # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in type expressions" |
| 111 | + # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in parameter annotations" |
112 | 112 | r: list[T][int], |
113 | | - # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in type expressions" |
| 113 | + # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in parameter annotations" |
114 | 114 | s: list[list[T][int]], |
115 | 115 | ): |
116 | 116 | reveal_type(a) # revealed: Unknown |
@@ -270,25 +270,25 @@ def bar() -> None: |
270 | 270 | async def baz(): ... |
271 | 271 | async def outer_async(): # avoid unrelated syntax errors on `yield` and `await` |
272 | 272 | def _( |
273 | | - a: "1", # error: [invalid-type-form] "Int literals are not allowed in this context in a type expression" |
274 | | - b: "2.3", # error: [invalid-type-form] "Float literals are not allowed in type expressions" |
275 | | - c: "4j", # error: [invalid-type-form] "Complex literals are not allowed in type expressions" |
276 | | - d: "True", # error: [invalid-type-form] "Boolean literals are not allowed in this context in a type expression" |
277 | | - e: "1 and 2", # error: [invalid-type-form] "Boolean operations are not allowed in type expressions" |
278 | | - f: "1 or 2", # error: [invalid-type-form] "Boolean operations are not allowed in type expressions" |
279 | | - g: "(foo := 1)", # error: [invalid-type-form] "Named expressions are not allowed in type expressions" |
280 | | - h: "not 1", # error: [invalid-type-form] "Unary operations are not allowed in type expressions" |
281 | | - i: "lambda: 1", # error: [invalid-type-form] "`lambda` expressions are not allowed in type expressions" |
282 | | - j: "1 if True else 2", # error: [invalid-type-form] "`if` expressions are not allowed in type expressions" |
283 | | - k: "await baz()", # error: [invalid-type-form] "`await` expressions are not allowed in type expressions" |
284 | | - l: "(yield 1)", # error: [invalid-type-form] "`yield` expressions are not allowed in type expressions" |
285 | | - m: "1 < 2", # error: [invalid-type-form] "Comparison expressions are not allowed in type expressions" |
286 | | - n: "bar()", # error: [invalid-type-form] "Function calls are not allowed in type expressions" |
287 | | - # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in type expressions" |
| 273 | + a: "1", # error: [invalid-type-form] "Int literals are not allowed in this context in a parameter annotation" |
| 274 | + b: "2.3", # error: [invalid-type-form] "Float literals are not allowed in parameter annotations" |
| 275 | + c: "4j", # error: [invalid-type-form] "Complex literals are not allowed in parameter annotations" |
| 276 | + d: "True", # error: [invalid-type-form] "Boolean literals are not allowed in this context in a parameter annotation" |
| 277 | + e: "1 and 2", # error: [invalid-type-form] "Boolean operations are not allowed in parameter annotations" |
| 278 | + f: "1 or 2", # error: [invalid-type-form] "Boolean operations are not allowed in parameter annotations" |
| 279 | + g: "(foo := 1)", # error: [invalid-type-form] "Named expressions are not allowed in parameter annotations" |
| 280 | + h: "not 1", # error: [invalid-type-form] "Unary operations are not allowed in parameter annotations" |
| 281 | + i: "lambda: 1", # error: [invalid-type-form] "`lambda` expressions are not allowed in parameter annotations" |
| 282 | + j: "1 if True else 2", # error: [invalid-type-form] "`if` expressions are not allowed in parameter annotations" |
| 283 | + k: "await baz()", # error: [invalid-type-form] "`await` expressions are not allowed in parameter annotations" |
| 284 | + l: "(yield 1)", # error: [invalid-type-form] "`yield` expressions are not allowed in parameter annotations" |
| 285 | + m: "1 < 2", # error: [invalid-type-form] "Comparison expressions are not allowed in parameter annotations" |
| 286 | + n: "bar()", # error: [invalid-type-form] "Function calls are not allowed in parameter annotations" |
| 287 | + # error: [invalid-type-form] "Only simple names and dotted names can be subscripted in parameter annotations" |
288 | 288 | o: "[1, 2, 3][1:2]", |
289 | | - # error: [invalid-type-form] "Only simple names, dotted names and subscripts can be used in type expressions" |
| 289 | + # error: [invalid-type-form] "Only simple names, dotted names and subscripts can be used in parameter annotations" |
290 | 290 | p: list[int].append, |
291 | | - # error: [invalid-type-form] "Only simple names, dotted names and subscripts can be used in type expressions" |
| 291 | + # error: [invalid-type-form] "Only simple names, dotted names and subscripts can be used in parameter annotations" |
292 | 292 | q: list[list[int].append], |
293 | 293 | ): |
294 | 294 | reveal_type(a) # revealed: Unknown |
@@ -319,17 +319,17 @@ python-version = "3.12" |
319 | 319 |
|
320 | 320 | ```py |
321 | 321 | def _( |
322 | | - a: {1: 2}, # error: [invalid-type-form] "Dict literals are not allowed in type expressions" |
323 | | - b: {1, 2}, # error: [invalid-type-form] "Set literals are not allowed in type expressions" |
324 | | - c: {k: v for k, v in [(1, 2)]}, # error: [invalid-type-form] "Dict comprehensions are not allowed in type expressions" |
325 | | - d: [k for k in [1, 2]], # error: [invalid-type-form] "List comprehensions are not allowed in type expressions" |
326 | | - e: {k for k in [1, 2]}, # error: [invalid-type-form] "Set comprehensions are not allowed in type expressions" |
327 | | - f: (k for k in [1, 2]), # error: [invalid-type-form] "Generator expressions are not allowed in type expressions" |
328 | | - # error: [invalid-type-form] "List literals are not allowed in this context in a type expression" |
| 322 | + a: {1: 2}, # error: [invalid-type-form] "Dict literals are not allowed in parameter annotations" |
| 323 | + b: {1, 2}, # error: [invalid-type-form] "Set literals are not allowed in parameter annotations" |
| 324 | + c: {k: v for k, v in [(1, 2)]}, # error: [invalid-type-form] "Dict comprehensions are not allowed in parameter annotations" |
| 325 | + d: [k for k in [1, 2]], # error: [invalid-type-form] "List comprehensions are not allowed in parameter annotations" |
| 326 | + e: {k for k in [1, 2]}, # error: [invalid-type-form] "Set comprehensions are not allowed in parameter annotations" |
| 327 | + f: (k for k in [1, 2]), # error: [invalid-type-form] "Generator expressions are not allowed in parameter annotations" |
| 328 | + # error: [invalid-type-form] "List literals are not allowed in this context in a parameter annotation" |
329 | 329 | g: [int, str], |
330 | | - # error: [invalid-type-form] "Tuple literals are not allowed in this context in a type expression: Did you mean `tuple[int, str]`?" |
| 330 | + # error: [invalid-type-form] "Tuple literals are not allowed in this context in a parameter annotation: Did you mean `tuple[int, str]`?" |
331 | 331 | h: (int, str), |
332 | | - i: (), # error: [invalid-type-form] "Tuple literals are not allowed in this context in a type expression: Did you mean `tuple[()]`?" |
| 332 | + i: (), # error: [invalid-type-form] "Tuple literals are not allowed in this context in a parameter annotation: Did you mean `tuple[()]`?" |
333 | 333 | ): |
334 | 334 | reveal_type(a) # revealed: Unknown |
335 | 335 | reveal_type(b) # revealed: Unknown |
|
0 commit comments