gh-128661: Remove DeprecationWarning in evaluate_forward_ref (#128930)

It doesn't make sense to use a deprecation for evaluate_forward_ref,
as it is a new function in Python 3.14 and doesn't have compatibility
guarantees.

I considered making it throw an error if type_params it not passed and
there is no owner. However, I think this is too unfriendly for users. The
case where this param is really needed is fairly esoteric and I don't think
this case is worth the pain of forcing users to write "type_params=()".
This commit is contained in:
Jelle Zijlstra 2025-04-03 09:52:17 -07:00 committed by GitHub
parent 24decb05dd
commit 5518c2ae09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 39 deletions

View file

@ -943,7 +943,7 @@ def evaluate_forward_ref(
owner=None,
globals=None,
locals=None,
type_params=_sentinel,
type_params=None,
format=annotationlib.Format.VALUE,
_recursive_guard=frozenset(),
):
@ -963,15 +963,12 @@ def evaluate_forward_ref(
infer the namespaces to use for looking up names. *globals* and *locals*
can also be explicitly given to provide the global and local namespaces.
*type_params* is a tuple of type parameters that are in scope when
evaluating the forward reference. This parameter must be provided (though
evaluating the forward reference. This parameter should be provided (though
it may be an empty tuple) if *owner* is not given and the forward reference
does not already have an owner set. *format* specifies the format of the
annotation and is a member of the annotationlib.Format enum.
"""
if type_params is _sentinel:
_deprecation_warning_for_no_type_params_passed("typing.evaluate_forward_ref")
type_params = ()
if format == annotationlib.Format.STRING:
return forward_ref.__forward_arg__
if forward_ref.__forward_arg__ in _recursive_guard: