-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Correctly process properties provided in mixins #7713
Conversation
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.
Thanks for the PR! Looks good, I just have couple suggestions.
mypy/checker.py
Outdated
@@ -1886,6 +1886,10 @@ class C(B, A[int]): ... # this is unsafe because... | |||
ok = is_subtype(first_sig, second_sig, ignore_pos_arg_names=True) | |||
elif first_type and second_type: | |||
ok = is_equivalent(first_type, second_type) | |||
if not ok and name in base2.abstract_attributes: |
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.
Maybe I am missing something but I think this should be OK even if name
is not abstract, so I would remove the right part of and
.
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.
I think you're right; I had considered only the abstract case. Fixed.
foo = "foo" | ||
class C(Mixin, A): | ||
pass | ||
[out] |
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.
I would add couple more tests with a non-abstract property that check:
- the error is still shown if you switch the order of bases in
C
. - the error is not shown if type in
Mixin
is a strict subtype of type in property (it is safe since it is read-only)
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.
Added some more tests.
This is an attempt at fixing the issue reported in #7631. I'm happy to address any issues that might be present in this first approach.
Fixes #7631