-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Loosen base class attribute compatibility checks when attribute is redefined #6585
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
Merged
ilevkivskyi
merged 4 commits into
python:master
from
syastrov:definition-in-base-class-incompatible-when-attr-redefined
Apr 12, 2019
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8e20acc
Loosen base class attribute compatibility checks when attribute is re…
syastrov 8adafdb
Remove extra newlines.
syastrov 3a38d4b
Restore the current behavior regarding incompatible type in assignment.
syastrov e807d81
Style fixes
ilevkivskyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
Prev
Previous commit
Next
Next commit
Remove extra newlines.
- Loading branch information
commit 8adafdb664946e296c33739fca0bb56b9657e085
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. A user might want to ignore the error once in the base class, instead of ignoring it in every subclass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slightly different than the above situation, as here, there was no error before.
I think it depends on how you want to interpret the
# type: ignore
.In the current behavior, because
B.x
has an ignore, you are no longer warned when you redefinex
inC.x
that that redefinition is actually incompatible with ancestor'sA.x
.A library author may have defined
B.x
with the ignore comment, and let us say that you are writing classC
yourself. I would find it unexpected that because the library author chose to add an ignore comment onB.x
that that would suppress a certain type of error when defining my own class.I may not know in detail how
B
is defined/type-annotated, so I may reasonably expect that the type checker would perform its normal checks for my definition of classC
(in this case, that it is compatible withA
).Are there other places in mypy where
# type: ignore
comments "spread" in that sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops:
(in this case, that it is compatible withA
)should be:
(in this case, that
C.x
is actually compatible withA.x
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Practically everywhere, an invalid type, a failed attribute access, an operator, or sometimes even failed function call, produce an
Any
type thus preventing subsequent errors.