Skip to content

Fix reflected operator priority for class objects - #22388

Open
Johnx-w wants to merge 1 commit into
python:masterfrom
Johnx-w:fix/metaclass-reflected-operator-priority
Open

Johnx-w wants to merge 1 commit into
python:masterfrom
Johnx-w:fix/metaclass-reflected-operator-priority

Conversation

@Johnx-w

@Johnx-w Johnx-w commented Nov 6, 2026 •

Copy link
Copy Markdown

Fixes #22377

Summary

 check_op_reversible
- compare constructor callable types
+ compare the class objects' runtime metaclasses

An overriding right-metaclass __rmul__ now takes priority. Inherited or unrelated reflected methods keep left-method priority.

Evidence

  • Before: New regression failed: Expression is of type "int", not "str".
    After: The regression passes.
  • check-classes.test: 619 passed, 1 xfailed; check-expressions.test: 202 passed.
  • Self-check: no issues in 349 source files. Black and Ruff passed.

Merge Danger

Door: two-way

Blast Radius: inference

Affects binary-operator result typing for class objects with related metaclasses.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

binary operator on class objects ignores the right operand's reflected method when its metaclass subclasses the left operand's metaclass

1 participant