https://github.com/python/cpython/commit/c89f76e6c4ca9b0200d5cc8cf0a675a76de50ba8
commit: c89f76e6c4ca9b0200d5cc8cf0a675a76de50ba8
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2025-07-06T22:11:13+03:00
summary:
gh-136021: Make `type_params` a required parameter for `typing._eval_type`
(#136332)
files:
A Misc/NEWS.d/next/Library/2025-07-06-10-18-48.gh-issue-136021.f-FJYT.rst
M Lib/test/test_typing.py
M Lib/typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index bef6773ad6cb2f..932c7b9c0a526b 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -6309,31 +6309,6 @@ def foo(a: 'whatevers') -> {}:
class InternalsTests(BaseTestCase):
- def test_deprecation_for_no_type_params_passed_to__evaluate(self):
- with self.assertWarnsRegex(
- DeprecationWarning,
- (
- "Failing to pass a value to the 'type_params' parameter "
- "of 'typing._eval_type' is deprecated"
- )
- ) as cm:
- self.assertEqual(typing._eval_type(list["int"], globals(), {}),
list[int])
-
- self.assertEqual(cm.filename, __file__)
-
- f = ForwardRef("int")
-
- with self.assertWarnsRegex(
- DeprecationWarning,
- (
- "Failing to pass a value to the 'type_params' parameter "
- "of 'typing.ForwardRef._evaluate' is deprecated"
- )
- ) as cm:
- self.assertIs(f._evaluate(globals(), {},
recursive_guard=frozenset()), int)
-
- self.assertEqual(cm.filename, __file__)
-
def test_collect_parameters(self):
typing = import_helper.import_fresh_module("typing")
with self.assertWarnsRegex(
diff --git a/Lib/typing.py b/Lib/typing.py
index 27105838a0a064..3ef377b954205f 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -437,10 +437,7 @@ def __repr__(self):
return '<sentinel>'
-_sentinel = _Sentinel()
-
-
-def _eval_type(t, globalns, localns, type_params=_sentinel, *,
recursive_guard=frozenset(),
+def _eval_type(t, globalns, localns, type_params, *,
recursive_guard=frozenset(),
format=None, owner=None):
"""Evaluate all forward references in the given type t.
@@ -448,9 +445,6 @@ def _eval_type(t, globalns, localns, type_params=_sentinel,
*, recursive_guard=f
recursive_guard is used to prevent infinite recursion with a recursive
ForwardRef.
"""
- if type_params is _sentinel:
- _deprecation_warning_for_no_type_params_passed("typing._eval_type")
- type_params = ()
if isinstance(t, _lazy_annotationlib.ForwardRef):
# If the forward_ref has __forward_module__ set, evaluate() infers the
globals
# from the module, and it will probably pick better than the globals
we have here.
diff --git
a/Misc/NEWS.d/next/Library/2025-07-06-10-18-48.gh-issue-136021.f-FJYT.rst
b/Misc/NEWS.d/next/Library/2025-07-06-10-18-48.gh-issue-136021.f-FJYT.rst
new file mode 100644
index 00000000000000..39a848c11eb8a1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-07-06-10-18-48.gh-issue-136021.f-FJYT.rst
@@ -0,0 +1,3 @@
+Make ``type_params`` parameter required in :func:`!typing._eval_type` after
+a deprecation period for not providing this parameter. Also remove the
+:exc:`DeprecationWarning` for the old behavior.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]