Skip to content

Fix type.__mro__ resolving to property - #16549

Open
crypt0lith wants to merge 1 commit into
python:mainfrom
crypt0lith:fix/type-mro-tuple-property
Open

crypt0lith wants to merge 1 commit into
python:mainfrom
crypt0lith:fix/type-mro-tuple-property

Conversation

@crypt0lith

Copy link
Copy Markdown

type.__mro__ resolves to property instead of tuple[type, ...]. type is in its own MRO, so attribute access resolves to the unbound getter instead of the actual attribute.

Replace the __mro__ property with __mro__: Final[tuple[type, ...]] to keep the attribute read-only without relying on the descriptor protocol, matching type.__dict__:

__dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment]

Minimal repro

reveal_type(type.__mro__)
reveal_type((*type.__mro__,))

pyright 1.1.414 gives the following error:

1:13 - information: Type of "type.__mro__" is "property"
2:13 - information: Type of "(*type.__mro__, )" is "tuple[Unknown, ...]"
2:14 - error: "property" is not iterable
  "__iter__" method not defined (reportGeneralTypeIssues)

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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.

1 participant