Feature or enhancement
Currently there are two places in our typing-related code that raise a DeprecationWarning when type_params parameter is not provided:
|
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:
|
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:
- Adding
TypeError('type_params parameter is not provided') when type_params is _sentinel
- Changing
type_params to not contain a default value
- Do nothing?
CC @JelleZijlstra @AlexWaygood
I would like to work on this after we decide the fate of these functions :)
Linked PRs
Feature or enhancement
Currently there are two places in our typing-related code that raise a
DeprecationWarningwhentype_paramsparameter is not provided:cpython/Lib/typing.py
Lines 432 to 442 in 07183eb
cpython/Lib/annotationlib.py
Lines 213 to 221 in 07183eb
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
So, we have several options:
TypeError('type_params parameter is not provided')whentype_params is _sentineltype_paramsto not contain a default valueCC @JelleZijlstra @AlexWaygood
I would like to work on this after we decide the fate of these functions :)
Linked PRs
type_paramsa required parameter fortyping._eval_type#136332typing#138120