Skip to content

Fix type.__mro__ resolving to property - #16549

Merged
srittau merged 1 commit into
python:mainfrom
crypt0lith:fix/type-mro-tuple-property
Oct 17, 2026
Merged

srittau merged 1 commit into
python:mainfrom
crypt0lith:fix/type-mro-tuple-property

Conversation

@crypt0lith

Copy link
Copy Markdown
Contributor

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. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, makes sense. We used to use @property for read-only attribute. This comes from a time before Final existed, so there may be more instances of this around.

@srittau
srittau merged commit 88a3ffb into python:main Oct 17, 2026
88 checks passed
@crypt0lith
crypt0lith deleted the fix/type-mro-tuple-property branch October 17, 2026 14:12
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.

2 participants