-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
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
Description
Feature or enhancement
Currently there are two places in our typing-related code that raise a DeprecationWarning when type_params parameter is not provided:
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 = () |
Lines 213 to 221 in 07183eb
| 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:
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:
- Adding
TypeError('type_params parameter is not provided')whentype_params is _sentinel - Changing
type_paramsto 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
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