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

Closed
wants to merge 13 commits into 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

@Daraan Daraan Nov 27, 2024

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. And as typing_extensions.ParamSpec.__new__ creates a typing.ParamSpec everything should be covered.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added & like noted in #489 for Concatenate a patch was necessary.

@JelleZijlstra
Copy link
Member

This is looking good, but could you fix the merge conflict?

(Sorry for the wait on these PRs!)

@JelleZijlstra JelleZijlstra self-requested a review December 13, 2024 15:33
@Daraan
Copy link
Contributor Author

Daraan commented Dec 14, 2024

#489 was a superset of this one with more changes. As that one made it in first closing this one.

@Daraan Daraan closed this Dec 14, 2024
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