Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Decide the fate of type_params in _eval_type and _evaluate #136021

Copy link
Copy link
@sobolevn

Description

@sobolevn
Issue body actions

Feature or enhancement

Currently there are two places in our typing-related code that raise a DeprecationWarning when type_params parameter is not provided:

cpython/Lib/typing.py

Lines 432 to 442 in 07183eb

def _eval_type(t, globalns, localns, type_params=_sentinel, *, 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 = ()

def _evaluate(self, globalns, localns, type_params=_sentinel, *, recursive_guard):
import typing
import warnings
if type_params is _sentinel:
typing._deprecation_warning_for_no_type_params_passed(
"typing.ForwardRef._evaluate"
)
type_params = ()

The error message of this function says that the behavior will change in 3.15 to disallow this:

cpython/Lib/typing.py

Lines 410 to 420 in 07183eb

def _deprecation_warning_for_no_type_params_passed(funcname: str) -> None:
import warnings
depr_message = (
f"Failing to pass a value to the 'type_params' parameter "
f"of {funcname!r} is deprecated, as it leads to incorrect behaviour "
f"when calling {funcname} on a stringified annotation "
f"that references a PEP 695 type parameter. "
f"It will be disallowed in Python 3.15."
)
warnings.warn(depr_message, category=DeprecationWarning, stacklevel=3)

So, we have several options:

  1. Adding TypeError('type_params parameter is not provided') when type_params is _sentinel
  2. Changing type_params to not contain a default value
  3. Do nothing?

CC @JelleZijlstra @AlexWaygood

I would like to work on this after we decide the fate of these functions :)

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.