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 attribute type resolution with multiple inheritance #18415

Merged

Conversation

sterliakov
Copy link
Contributor

Fixes #18268. Fixes #9319. Fixes #14279. Fixes #9031.

Supersedes #18270 as requested by @ilevkivskyi.

This PR introduces two changes:

  • Add missing map_type_from_supertype when checking generic attributes
  • Only compare the first base defining a name to all following in MRO - others are not necessarily pairwise compatible.

This comment has been minimized.

This comment has been minimized.

@sterliakov sterliakov marked this pull request as ready for review January 5, 2025 02:21
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Nice, will leave for Ivan but had small comment

test-data/unit/check-multiple-inheritance.test Outdated Show resolved Hide resolved
pass

class D(D0,D1,C):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we expect an error for something like:

class D3(D0,D1,C):
    class M(A.M):
        pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We certainly should expect an error there as such an override violates LSP. But overrides are checked elsewhere, I'm only modifying inherited attributes compatibility checks in this PR.

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

xarray (https://github.com/pydata/xarray)
+ xarray/core/groupby.py:1610: error: Unused "type: ignore" comment  [unused-ignore]
+ xarray/core/groupby.py:1778: error: Unused "type: ignore" comment  [unused-ignore]
+ xarray/core/resample.py:236: error: Unused "type: ignore" comment  [unused-ignore]
+ xarray/core/resample.py:379: error: Unused "type: ignore" comment  [unused-ignore]

ibis (https://github.com/ibis-project/ibis)
- ibis/common/collections.py:280: error: Definition of "get" in base class "Mapping" is incompatible with definition in base class "Mapping"  [misc]

@ilevkivskyi ilevkivskyi merged commit d86b1e5 into python:master Jan 11, 2025
18 checks passed
ilevkivskyi pushed a commit that referenced this pull request Jan 11, 2025
…operty (#18441)

Fixes #18189.

Following #18415, this fixes one more place where parent class generics
aren't mapped to attributes correctly.

---------

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants