Skip to content

Commit bc68f2e

Browse files
committed
gh-128661: Remove DeprecationWarning in evaluate_forward_ref
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=()".
1 parent ea6cc26 commit bc68f2e

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

Doc/library/annotationlib.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ Classes
192192
the global and local namespaces in which the name is evaluated.
193193
*type_params*, if given, must be a tuple of
194194
:ref:`type parameters <type-params>` that are in scope while the forward
195-
reference is being evaluated. *owner* is the object that owns the
195+
reference is being evaluated. This parameter should be provided (though it
196+
may be an empty tuple) if the *owner* parameter is not given and the
197+
:class:`~ForwardRef` instance does not have an owner set.
198+
*owner* is the object that owns the
196199
annotation from which the forward reference derives, usually a function,
197200
class, or module.
198201

Doc/library/typing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,7 @@ Introspection helpers
34393439
the global and local namespaces.
34403440
*type_params* is a tuple of :ref:`type parameters <type-params>` that
34413441
are in scope when evaluating the forward reference.
3442-
This parameter must be provided (though it may be an empty tuple) if *owner*
3442+
This parameter should be provided (though it may be an empty tuple) if *owner*
34433443
is not given and the forward reference does not already have an owner set.
34443444
*format* specifies the format of the annotation and is a member of
34453445
the :class:`annotationlib.Format` enum.

Lib/test/test_typing.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7284,20 +7284,7 @@ def test_evaluate_forward_ref(self):
72847284

72857285
def test_evaluate_forward_ref_no_type_params(self):
72867286
ref = ForwardRef('int')
7287-
with self.assertWarnsRegex(
7288-
DeprecationWarning,
7289-
(
7290-
"Failing to pass a value to the 'type_params' parameter "
7291-
"of 'typing.evaluate_forward_ref' is deprecated, "
7292-
"as it leads to incorrect behaviour"
7293-
),
7294-
):
7295-
typing.evaluate_forward_ref(ref)
7296-
7297-
# No warnings when `type_params` is passed:
7298-
with warnings.catch_warnings(record=True) as w:
7299-
typing.evaluate_forward_ref(ref, type_params=())
7300-
self.assertEqual(w, [])
7287+
self.assertIs(typing.evaluate_forward_ref(ref), int)
73017288

73027289

73037290
class CollectionsAbcTests(BaseTestCase):

Lib/typing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def evaluate_forward_ref(
10241024
owner=None,
10251025
globals=None,
10261026
locals=None,
1027-
type_params=_sentinel,
1027+
type_params=None,
10281028
format=annotationlib.Format.VALUE,
10291029
_recursive_guard=frozenset(),
10301030
):
@@ -1044,15 +1044,12 @@ def evaluate_forward_ref(
10441044
infer the namespaces to use for looking up names. *globals* and *locals*
10451045
can also be explicitly given to provide the global and local namespaces.
10461046
*type_params* is a tuple of type parameters that are in scope when
1047-
evaluating the forward reference. This parameter must be provided (though
1047+
evaluating the forward reference. This parameter should be provided (though
10481048
it may be an empty tuple) if *owner* is not given and the forward reference
10491049
does not already have an owner set. *format* specifies the format of the
10501050
annotation and is a member of the annotationlib.Format enum.
10511051
10521052
"""
1053-
if type_params is _sentinel:
1054-
_deprecation_warning_for_no_type_params_passed("typing.evaluate_forward_ref")
1055-
type_params = ()
10561053
if format == annotationlib.Format.STRING:
10571054
return forward_ref.__forward_arg__
10581055
if forward_ref.__forward_arg__ in _recursive_guard:

0 commit comments

Comments
 (0)