File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -2900,12 +2900,19 @@ def relevant_items(self) -> list[Type]:
29002900 return [i for i in self .items if not isinstance (get_proper_type (i ), NoneType )]
29012901
29022902 def serialize (self ) -> JsonDict :
2903- return {".class" : "UnionType" , "items" : [t .serialize () for t in self .items ]}
2903+ return {
2904+ ".class" : "UnionType" ,
2905+ "items" : [t .serialize () for t in self .items ],
2906+ "uses_pep604_syntax" : self .uses_pep604_syntax ,
2907+ }
29042908
29052909 @classmethod
29062910 def deserialize (cls , data : JsonDict ) -> UnionType :
29072911 assert data [".class" ] == "UnionType"
2908- return UnionType ([deserialize_type (t ) for t in data ["items" ]])
2912+ return UnionType (
2913+ [deserialize_type (t ) for t in data ["items" ]],
2914+ uses_pep604_syntax = data ["uses_pep604_syntax" ],
2915+ )
29092916
29102917
29112918class PartialType (ProperType ):
Original file line number Diff line number Diff line change @@ -6726,3 +6726,20 @@ from typing_extensions import TypeIs
67266726def guard(x: object) -> TypeIs[int]:
67276727 pass
67286728[builtins fixtures/tuple.pyi]
6729+
6730+ [case testStartUsingPEP604Union]
6731+ # flags: --python-version 3.10
6732+ import a
6733+ [file a.py]
6734+ import lib
6735+
6736+ [file a.py.2]
6737+ from lib import IntOrStr
6738+ assert isinstance(1, IntOrStr)
6739+
6740+ [file lib.py]
6741+ from typing_extensions import TypeAlias
6742+
6743+ IntOrStr: TypeAlias = int | str
6744+ assert isinstance(1, IntOrStr)
6745+ [builtins fixtures/type.pyi]
You can’t perform that action at this time.
0 commit comments