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 overriding partial-type attribute with method #12943

Merged
merged 1 commit into from Jul 8, 2022

Conversation

jakelishman
Copy link
Contributor

Description

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.

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 @property itself, though, but any method overriding a value with partially inferred type.

Fixes #11686
Fixes #11981

Test Plan

Added test case to check-classes.test.

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.
@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@jakelishman
Copy link
Contributor Author

Hi all - apologies for the bump, I just wanted to ask if this bug fix is being considered? Thanks!

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, thanks for the PR! It's always great to have fixes to crashes.

@JukkaL JukkaL merged commit 9f99400 into python:master Jul 8, 2022
@jakelishman jakelishman deleted the fix/crash-override-partial-type branch July 8, 2022 14:08
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
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.

Crash when analysing qiskit Crash when overriding partially typed attribute with partially typed property
2 participants