Fix crash overriding partial-type attribute with method#12943
Merged
Conversation
Attributes can still be partially typed (e.g. `<partial list[?]>`) after a parent-class definition if the block they are declared in is deferred. The first pass for child classes might then encounter this type when considering method overrides, which could cause a crash when attempting to determine subtype compatibility.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Contributor
Author
|
Hi all - apologies for the bump, I just wanted to ask if this bug fix is being considered? Thanks! |
JukkaL
approved these changes
Jul 8, 2022
Collaborator
JukkaL
left a comment
There was a problem hiding this comment.
Looks good, thanks for the PR! It's always great to have fixes to crashes.
Gobot1234
pushed a commit
to Gobot1234/mypy
that referenced
this pull request
Aug 12, 2022
Attributes can still be partially typed (e.g. `<partial list[?]>`) after a parent-class definition if the block they are declared in is deferred. The first pass for child classes might then encounter this type when considering method overrides, which could cause a crash when attempting to determine subtype compatibility. Fixes python#11686 Fixes python#11981
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Attributes can still be partially typed (e.g.
<partial list[?]>) aftera parent-class definition if the block they are declared in is deferred.
The first pass for child classes might then encounter this type when
considering method overrides, which could cause a crash when attempting
to determine subtype compatibility.
This patch causes the subtype checker to defer the override test if the original type is still partial, avoiding the crash. The correct error messages are still reported after this. This is the same approach as suggested by #11686 (comment), but the test case is different to the original issue. The original reproducer involved
@property, which runs afoul of #4125, and a full fix there is likely better part of #7724. The behaviour is not caused by@propertyitself, though, but any method overriding a value with partially inferred type.Fixes #11686
Fixes #11981
Test Plan
Added test case to
check-classes.test.