File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -7819,6 +7819,10 @@ def test_or(self):
78197819 self .assertEqual (Alias | None , Union [Alias , None ])
78207820 self .assertEqual (Alias | (int | str ), Union [Alias , int | str ])
78217821 self .assertEqual (Alias | list [float ], Union [Alias , list [float ]])
7822+
7823+ if sys .version_info >= (3 , 12 ):
7824+ Alias2 = typing .TypeAliasType ("Alias2" , str )
7825+ self .assertEqual (Alias | Alias2 , Union [Alias , Alias2 ])
78227826 else :
78237827 with self .assertRaises (TypeError ):
78247828 Alias | int
Original file line number Diff line number Diff line change @@ -3827,14 +3827,27 @@ def __ror__(self, other):
38273827 TypeAliasType = typing .TypeAliasType
38283828# 3.8-3.13
38293829else :
3830- def _is_unionable (obj ):
3831- """Corresponds to is_unionable() in unionobject.c in CPython."""
3832- return obj is None or isinstance (obj , (
3833- type ,
3834- _types .GenericAlias ,
3835- _types .UnionType ,
3836- TypeAliasType ,
3837- ))
3830+ if sys .version_info >= (3 , 12 ):
3831+ # 3.12-3.14
3832+ def _is_unionable (obj ):
3833+ """Corresponds to is_unionable() in unionobject.c in CPython."""
3834+ return obj is None or isinstance (obj , (
3835+ type ,
3836+ _types .GenericAlias ,
3837+ _types .UnionType ,
3838+ typing .TypeAliasType ,
3839+ TypeAliasType ,
3840+ ))
3841+ else :
3842+ # 3.8-3.11
3843+ def _is_unionable (obj ):
3844+ """Corresponds to is_unionable() in unionobject.c in CPython."""
3845+ return obj is None or isinstance (obj , (
3846+ type ,
3847+ _types .GenericAlias ,
3848+ _types .UnionType ,
3849+ TypeAliasType ,
3850+ ))
38383851
38393852 if sys .version_info < (3 , 10 ):
38403853 # Copied and pasted from https://github.com/python/cpython/blob/986a4e1b6fcae7fe7a1d0a26aea446107dd58dd2/Objects/genericaliasobject.c#L568-L582,
You can’t perform that action at this time.
0 commit comments