Skip to content

gh-136021: Make type_params a required parameter for typing._eval_type #136332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 1 addition & 7 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,14 @@ 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.

For use of globalns and localns see the docstring for get_type_hints().
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy