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

Correctly process properties provided in mixins #7713

Merged
merged 4 commits into from
Oct 16, 2019
Merged

Correctly process properties provided in mixins #7713

merged 4 commits into from
Oct 16, 2019

Conversation

Xyene
Copy link
Contributor

@Xyene Xyene commented Oct 15, 2019

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

Copy link
Member

@ilevkivskyi ilevkivskyi left a 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:
Copy link
Member

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.

Copy link
Contributor Author

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]
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some more tests.

@Xyene Xyene changed the title Correctly process abstract properties provided in mixins Correctly process properties provided in mixins Oct 16, 2019
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.

Using mypy with mixins and abstract properties
2 participants