@@ -2072,7 +2072,7 @@ def _create_concatenate_alias(origin, parameters):
2072
2072
if parameters [- 1 ] is ... and sys .version_info < (3 , 9 , 2 ):
2073
2073
# Hack: Arguments must be types, replace it with one.
2074
2074
parameters = (* parameters [:- 1 ], _EllipsisDummy )
2075
- if sys .version_info >= (3 , 10 , 2 ):
2075
+ if sys .version_info >= (3 , 10 , 3 ):
2076
2076
concatenate = _ConcatenateGenericAlias (origin , parameters ,
2077
2077
_typevar_types = (TypeVar , ParamSpec ),
2078
2078
_paramspec_tvars = True )
@@ -3123,7 +3123,8 @@ def method(self) -> None:
3123
3123
return arg
3124
3124
3125
3125
3126
- if hasattr (warnings , "deprecated" ):
3126
+ # Python 3.13.3+ contains a fix for the wrapped __new__
3127
+ if sys .version_info >= (3 , 13 , 3 ):
3127
3128
deprecated = warnings .deprecated
3128
3129
else :
3129
3130
_T = typing .TypeVar ("_T" )
@@ -3203,7 +3204,7 @@ def __call__(self, arg: _T, /) -> _T:
3203
3204
original_new = arg .__new__
3204
3205
3205
3206
@functools .wraps (original_new )
3206
- def __new__ (cls , * args , ** kwargs ):
3207
+ def __new__ (cls , / , * args , ** kwargs ):
3207
3208
if cls is arg :
3208
3209
warnings .warn (msg , category = category , stacklevel = stacklevel + 1 )
3209
3210
if original_new is not object .__new__ :
@@ -3827,14 +3828,27 @@ def __ror__(self, other):
3827
3828
TypeAliasType = typing .TypeAliasType
3828
3829
# 3.8-3.13
3829
3830
else :
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
- ))
3831
+ if sys .version_info >= (3 , 12 ):
3832
+ # 3.12-3.14
3833
+ def _is_unionable (obj ):
3834
+ """Corresponds to is_unionable() in unionobject.c in CPython."""
3835
+ return obj is None or isinstance (obj , (
3836
+ type ,
3837
+ _types .GenericAlias ,
3838
+ _types .UnionType ,
3839
+ typing .TypeAliasType ,
3840
+ TypeAliasType ,
3841
+ ))
3842
+ else :
3843
+ # 3.8-3.11
3844
+ def _is_unionable (obj ):
3845
+ """Corresponds to is_unionable() in unionobject.c in CPython."""
3846
+ return obj is None or isinstance (obj , (
3847
+ type ,
3848
+ _types .GenericAlias ,
3849
+ _types .UnionType ,
3850
+ TypeAliasType ,
3851
+ ))
3838
3852
3839
3853
if sys .version_info < (3 , 10 ):
3840
3854
# Copied and pasted from https://github.com/python/cpython/blob/986a4e1b6fcae7fe7a1d0a26aea446107dd58dd2/Objects/genericaliasobject.c#L568-L582,
@@ -4371,7 +4385,11 @@ def _lax_type_check(
4371
4385
A lax Python 3.11+ like version of typing._type_check
4372
4386
"""
4373
4387
if hasattr (typing , "_type_convert" ):
4374
- if _FORWARD_REF_HAS_CLASS :
4388
+ if (
4389
+ sys .version_info >= (3 , 10 , 3 )
4390
+ or (3 , 9 , 10 ) < sys .version_info [:3 ] < (3 , 10 )
4391
+ ):
4392
+ # allow_special_forms introduced later cpython/#30926 (bpo-46539)
4375
4393
type_ = typing ._type_convert (
4376
4394
value ,
4377
4395
module = module ,
0 commit comments