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 crash on invalid type variable with ParamSpec #15953

Merged
merged 4 commits into from Aug 25, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #15948

The fix is straightforward: invalid type variable resulted in applying type arguments packing/simplification when we shouldn't. Making the latter more strict fixes the issue.

cc @A5rocks

mypy/typeanal.py Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

ilevkivskyi and others added 2 commits August 24, 2023 22:49
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@ilevkivskyi
Copy link
Member Author

@hauntsaninja zetta_utils is a great addition: caught an actual bug in my PR.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks good, I have just one idea.

return list(an_args)
if any(isinstance(a, (Parameters, ParamSpecType)) for a in an_args):
# Nested parameter specifications are not allowed.
return list(an_args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another option might be to generate an error and return a list with a single any type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, currently this will say something like "Too many arguments", I will check if we can make error messages better on this.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi ilevkivskyi merged commit f9b1db6 into python:master Aug 25, 2023
18 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-paramspec-crash-2 branch August 25, 2023 20:41
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.

INTERNAL ERROR: Parameters cannot be constrained to (1.5.1) / AssertionError (HEAD)
3 participants