File tree 2 files changed +26
-2
lines changed 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -2898,12 +2898,19 @@ def relevant_items(self) -> list[Type]:
2898
2898
return [i for i in self .items if not isinstance (get_proper_type (i ), NoneType )]
2899
2899
2900
2900
def serialize (self ) -> JsonDict :
2901
- return {".class" : "UnionType" , "items" : [t .serialize () for t in self .items ]}
2901
+ return {
2902
+ ".class" : "UnionType" ,
2903
+ "items" : [t .serialize () for t in self .items ],
2904
+ "uses_pep604_syntax" : self .uses_pep604_syntax ,
2905
+ }
2902
2906
2903
2907
@classmethod
2904
2908
def deserialize (cls , data : JsonDict ) -> UnionType :
2905
2909
assert data [".class" ] == "UnionType"
2906
- return UnionType ([deserialize_type (t ) for t in data ["items" ]])
2910
+ return UnionType (
2911
+ [deserialize_type (t ) for t in data ["items" ]],
2912
+ uses_pep604_syntax = data ["uses_pep604_syntax" ],
2913
+ )
2907
2914
2908
2915
2909
2916
class PartialType (ProperType ):
Original file line number Diff line number Diff line change @@ -6726,3 +6726,20 @@ from typing_extensions import TypeIs
6726
6726
def guard(x: object) -> TypeIs[int]:
6727
6727
pass
6728
6728
[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