-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Don't turn list defaults for ParamSpecs into tuples #394
Conversation
src/typing_extensions.py
Outdated
type_param.__default__ = type(default)( | ||
typing._type_check(d, "Default must be a type") for d in default | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _type_check()
calls here feel "morally correct" in a sense -- they're consistent with what a lot of the rest of the typing.py internals do. But on the other hand, CPython doesn't actually do any check at all in its 3.13 implementation; it just sets the __default__
attribute to the value passed in, and moves on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe we should just do that here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether the bug was that we were being too lenient or that CPython wasn't being restrictive enough. But having slept on it, I now agree that we should just accept any default value, and not do any type checking here. That's consistent with what CPython has always done for TypeVar bounds and TypeVar constraints, which should also conceptually be types:
% pyenv local 3.11 % python
Python 3.11.8 (main, Feb 15 2024, 19:32:18) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import TypeVar
>>> def not_a_type(): pass
...
>>> T = TypeVar("T", bound=not_a_type)
>>> U = TypeVar("U", not_a_type, not_a_type)
src/typing_extensions.py
Outdated
type_param.__default__ = type(default)( | ||
typing._type_check(d, "Default must be a type") for d in default | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe we should just do that here too?
PEP 696 specifies that default values for ParamSpecs must be lists, and CPython on 3.13 keeps them as a list for the
__default__
attribute:Currently in the
typing_extensions
version, however, we turn any list into a tuple, which seems wrong:This PR fixes that.