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]:
2900
2900
return [i for i in self .items if not isinstance (get_proper_type (i ), NoneType )]
2901
2901
2902
2902
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
+ }
2904
2908
2905
2909
@classmethod
2906
2910
def deserialize (cls , data : JsonDict ) -> UnionType :
2907
2911
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
+ )
2909
2916
2910
2917
2911
2918
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