@@ -251,3 +251,65 @@ foo: ReadableBuffer
251251[file was_mmap.py]
252252from was_builtins import *
253253class mmap: ...
254+
255+ [case testUnionOrSyntaxWithQuotedOperandsNotAllowed]
256+ # flags: --python-version 3.10
257+ from typing import Union, assert_type
258+
259+ x1: "int" | str # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
260+ x2: int | "str" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
261+ x3: int | str | "bytes" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
262+ assert_type(x1, Union[int, str])
263+ assert_type(x2, Union[int, str])
264+ assert_type(x3, Union[int, str, bytes])
265+
266+ [case testUnionOrSyntaxWithQuotedOperandsWithTypeVar]
267+ # flags: --python-version 3.10
268+ import types
269+ from typing import TypeVar, Union, assert_type
270+ from typing_extensions import TypeAlias
271+
272+ T = TypeVar("T")
273+
274+ ok1: TypeAlias = T | "int"
275+ ok2: TypeAlias = "int" | T
276+ ok3: TypeAlias = int | T | "str"
277+ ok4: TypeAlias = "int" | T | "str"
278+ ok5: TypeAlias = T | "int" | str
279+ ok6: TypeAlias = T | int | "str"
280+ ok7: TypeAlias = list["str" | T]
281+
282+ bad1: TypeAlias = "T" | "int" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
283+ bad2: TypeAlias = int | "str" | T # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
284+ bad3: TypeAlias = list["str" | int] # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
285+ [builtins fixtures/tuple.pyi]
286+
287+ [case testUnionOrSyntaxWithQuotedOperandsWithAlias]
288+ # flags: --python-version 3.10
289+ import types
290+ from typing import TypeVar
291+ from typing_extensions import TypeAlias
292+
293+ T = TypeVar("T")
294+
295+ A1: TypeAlias = int
296+ A2: TypeAlias = int | str
297+ A3: TypeAlias = list[T]
298+ A4: TypeAlias = T | str
299+
300+ x1: A1 | "bytes" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
301+ x2: A2 | "bytes" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
302+ x3: A3[int] | "bytes" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
303+ x4: A4[int] | "bytes" # ok
304+ [builtins fixtures/tuple.pyi]
305+
306+ [case testUnionOrSyntaxWithQuotedOperandsFutureAnnotations]
307+ # flags: --python-version 3.10
308+ from __future__ import annotations
309+ import types
310+ from typing_extensions import TypeAlias
311+
312+ x1: int | "str" # ok
313+ def f(x: int | "str"): pass # ok
314+ x2: TypeAlias = int | "str" # E: X | Y syntax for unions cannot use quoted operands; use quotes around the entire expression instead
315+ [builtins fixtures/tuple.pyi]
0 commit comments