Skip to content
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

Fix Generic with ParamSpec not subscriptable with multiple arguments [non-generic-variant] #491

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Daraan
Copy link
Contributor

@Daraan Daraan commented Oct 23, 2024

This PR assures that no TypeError is raised, however there are still multiple limitations for Python <3.11.3

I think some of the 3.10 cases could be a regression; I am still looking into that and will create a separate issue. #489 will fix most of the cases as a follow up of this PR.

@Daraan
Copy link
Contributor Author

Daraan commented Oct 28, 2024

Note changes here are the combined checks from _prepare_paramspec_params(cls, params) and Generic.__class_getitem__ that would normally not execute _check_generic in 3.10+

# we do not check the count
if (inspect.isclass(cls) and issubclass(cls, typing.Generic)
and len(cls.__parameters__) == 1
and isinstance(cls.__parameters__[0], ParamSpec)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check both typing.ParamSpec and typing_extensions.ParamSpec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think so. For 3.10 the _TypeVarLikeMeta __instancecheck__ of typing_extensions.ParamSpec will check for the typing variant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be useful to have a test on 3.10+ that uses typing.Concatenate and typing.ParamSpec, which are different from the typing_extensions version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic with ParamSpec raise TypeError
2 participants