Skip to content

Commit eff7eca

Browse files
committed
gh-136021: Make type_params a required parameter for typing._eval_type
1 parent 1953713 commit eff7eca

File tree

3 files changed

+4
-32
lines changed

3 files changed

+4
-32
lines changed

Lib/test/test_typing.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6309,31 +6309,6 @@ def foo(a: 'whatevers') -> {}:
63096309

63106310

63116311
class InternalsTests(BaseTestCase):
6312-
def test_deprecation_for_no_type_params_passed_to__evaluate(self):
6313-
with self.assertWarnsRegex(
6314-
DeprecationWarning,
6315-
(
6316-
"Failing to pass a value to the 'type_params' parameter "
6317-
"of 'typing._eval_type' is deprecated"
6318-
)
6319-
) as cm:
6320-
self.assertEqual(typing._eval_type(list["int"], globals(), {}), list[int])
6321-
6322-
self.assertEqual(cm.filename, __file__)
6323-
6324-
f = ForwardRef("int")
6325-
6326-
with self.assertWarnsRegex(
6327-
DeprecationWarning,
6328-
(
6329-
"Failing to pass a value to the 'type_params' parameter "
6330-
"of 'typing.ForwardRef._evaluate' is deprecated"
6331-
)
6332-
) as cm:
6333-
self.assertIs(f._evaluate(globals(), {}, recursive_guard=frozenset()), int)
6334-
6335-
self.assertEqual(cm.filename, __file__)
6336-
63376312
def test_collect_parameters(self):
63386313
typing = import_helper.import_fresh_module("typing")
63396314
with self.assertWarnsRegex(

Lib/typing.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,14 @@ def __repr__(self):
437437
return '<sentinel>'
438438

439439

440-
_sentinel = _Sentinel()
441-
442-
443-
def _eval_type(t, globalns, localns, type_params=_sentinel, *, recursive_guard=frozenset(),
440+
def _eval_type(t, globalns, localns, type_params, *, recursive_guard=frozenset(),
444441
format=None, owner=None):
445442
"""Evaluate all forward references in the given type t.
446443
447444
For use of globalns and localns see the docstring for get_type_hints().
448445
recursive_guard is used to prevent infinite recursion with a recursive
449446
ForwardRef.
450447
"""
451-
if type_params is _sentinel:
452-
_deprecation_warning_for_no_type_params_passed("typing._eval_type")
453-
type_params = ()
454448
if isinstance(t, _lazy_annotationlib.ForwardRef):
455449
# If the forward_ref has __forward_module__ set, evaluate() infers the globals
456450
# from the module, and it will probably pick better than the globals we have here.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make ``type_params`` parameter required in :func:`!typing._eval_type` after
2+
a deprecation period for not providing this parameter. Also remove the
3+
:exc:`DeprecationWarning` for the old behavior.

0 commit comments

Comments
 (0)