@@ -437,13 +437,38 @@ def inner(*args, **kwds):
437
437
return decorator
438
438
439
439
440
- def _eval_type (t , globalns , localns , type_params = None , * , recursive_guard = frozenset ()):
440
+ def _deprecation_warning_for_no_type_params_passed (funcname : str ) -> None :
441
+ import warnings
442
+
443
+ depr_message = (
444
+ f"Failing to pass a value to the 'type_params' parameter "
445
+ f"of { funcname !r} is deprecated, as it leads to incorrect behaviour "
446
+ f"when calling { funcname } on a stringified annotation "
447
+ f"that references a PEP 695 type parameter. "
448
+ f"It will be disallowed in Python 3.15."
449
+ )
450
+ warnings .warn (depr_message , category = DeprecationWarning , stacklevel = 3 )
451
+
452
+
453
+ class _Sentinel :
454
+ __slots__ = ()
455
+ def __repr__ (self ):
456
+ return '<sentinel>'
457
+
458
+
459
+ _sentinel = _Sentinel ()
460
+
461
+
462
+ def _eval_type (t , globalns , localns , type_params = _sentinel , * , recursive_guard = frozenset ()):
441
463
"""Evaluate all forward references in the given type t.
442
464
443
465
For use of globalns and localns see the docstring for get_type_hints().
444
466
recursive_guard is used to prevent infinite recursion with a recursive
445
467
ForwardRef.
446
468
"""
469
+ if type_params is _sentinel :
470
+ _deprecation_warning_for_no_type_params_passed ("typing._eval_type" )
471
+ type_params = ()
447
472
if isinstance (t , ForwardRef ):
448
473
return t ._evaluate (globalns , localns , type_params , recursive_guard = recursive_guard )
449
474
if isinstance (t , (_GenericAlias , GenericAlias , types .UnionType )):
@@ -1018,7 +1043,10 @@ def __init__(self, arg, is_argument=True, module=None, *, is_class=False):
1018
1043
self .__forward_is_class__ = is_class
1019
1044
self .__forward_module__ = module
1020
1045
1021
- def _evaluate (self , globalns , localns , type_params = None , * , recursive_guard ):
1046
+ def _evaluate (self , globalns , localns , type_params = _sentinel , * , recursive_guard ):
1047
+ if type_params is _sentinel :
1048
+ _deprecation_warning_for_no_type_params_passed ("typing.ForwardRef._evaluate" )
1049
+ type_params = ()
1022
1050
if self .__forward_arg__ in recursive_guard :
1023
1051
return self
1024
1052
if not self .__forward_evaluated__ or localns is not globalns :
@@ -2998,15 +3026,6 @@ def __new__(cls, typename, bases, ns):
2998
3026
return nm_tpl
2999
3027
3000
3028
3001
- class _Sentinel :
3002
- __slots__ = ()
3003
- def __repr__ (self ):
3004
- return '<sentinel>'
3005
-
3006
-
3007
- _sentinel = _Sentinel ()
3008
-
3009
-
3010
3029
def NamedTuple (typename , fields = _sentinel , / , ** kwargs ):
3011
3030
"""Typed version of namedtuple.
3012
3031
0 commit comments