@@ -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,
@@ -4376,7 +4389,11 @@ def _lax_type_check(
43764389 A lax Python 3.11+ like version of typing._type_check
43774390 """
43784391 if hasattr (typing , "_type_convert" ):
4379- if _FORWARD_REF_HAS_CLASS :
4392+ if (
4393+ sys .version_info >= (3 , 10 , 3 )
4394+ or (3 , 9 , 10 ) < sys .version_info [:3 ] < (3 , 10 )
4395+ ):
4396+ # allow_special_forms introduced later cpython/#30926 (bpo-46539)
43804397 type_ = typing ._type_convert (
43814398 value ,
43824399 module = module ,
0 commit comments