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

add types.GenericAlias.__mro_entries__ #13284

Merged
merged 3 commits into from
Jan 15, 2025
Merged

Conversation

tungol
Copy link
Contributor

@tungol tungol commented Dec 23, 2024

I used Iterable[object] because it matches the call signature of resolve_bases, but it could just as easily be Any because the specific implementation here doesn't look at the argument and always returns a 1-tuple of the __origin__ attribute.

This comment has been minimized.

@tungol tungol marked this pull request as draft December 23, 2024 20:10
@tungol tungol marked this pull request as ready for review December 23, 2024 20:11
@tungol
Copy link
Contributor Author

tungol commented Dec 23, 2024

steam.py has a custom subclass of GenericAlias which defines a __mro_entries__ as def __mro_entries__(self, bases: tuple[type, ...]) -> tuple[type]:. That's what I probably would have gone with here myself if I hadn't seen the discussion for types.resolve_bases.

This comment has been minimized.

stdlib/types.pyi Outdated Show resolved Hide resolved
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
@AlexWaygood AlexWaygood reopened this Jan 14, 2025
Copy link
Contributor

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

steam.py (https://github.com/Gobot1234/steam.py)
+ steam/trade.py:189: error: Argument 1 of "__mro_entries__" is incompatible with supertype "GenericAlias"; supertype defines the argument type as "Iterable[object]"  [override]
+ steam/trade.py:189: note: This violates the Liskov substitution principle
+ steam/trade.py:189: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides

schemathesis (https://github.com/schemathesis/schemathesis)
-   File "/tmp/mypy_primer/old_mypy/venv/bin/mypy", line 8, in <module>
+   File "/tmp/mypy_primer/new_mypy/venv/bin/mypy", line 8, in <module>
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks!

@srittau srittau merged commit 578af27 into python:main Jan 15, 2025
56 of 109 checks passed
@tungol tungol deleted the mro_entries branch January 15, 2025 18:00
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.

3 participants