Skip to content

Fix crash on invalid type variable with ParamSpec#15953

Merged
ilevkivskyi merged 4 commits intopython:masterfrom
ilevkivskyi:fix-paramspec-crash-2
Aug 25, 2023
Merged

Fix crash on invalid type variable with ParamSpec#15953
ilevkivskyi merged 4 commits intopython:masterfrom
ilevkivskyi:fix-paramspec-crash-2

Conversation

@ilevkivskyi
Copy link
Copy Markdown
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

Comment thread mypy/typeanal.py Outdated
@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
Copy Markdown
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
Copy Markdown
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.

Comment thread mypy/typeanal.py
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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