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 @@ -2898,12 +2898,19 @@ def relevant_items(self) -> list[Type]:
28982898 return [i for i in self .items if not isinstance (get_proper_type (i ), NoneType )]
28992899
29002900 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+ }
29022906
29032907 @classmethod
29042908 def deserialize (cls , data : JsonDict ) -> UnionType :
29052909 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+ )
29072914
29082915
29092916class 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