Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
chrikrah
approved these changes
Nov 7, 2026
chrikrah
left a comment
There was a problem hiding this comment.
Mergeable from my side; reverting the fix fails the new test.
- non-blocking:
type[A] * type[B]still infersint, runtimestr; TypeType isn't unwrapped.
$ python -m mypy probe.py # A*B, A*C, A*D, SubA*SubB, A*SubB, A*RightMeta(...); f(x: type[A], y: type[B]) reveals x*y
base 55472c0: Found 4 errors in 1 file (Expression is of type "int", not "str"); probe.py:26: note: Revealed type is "int"
head 1903600: Success: no issues found in 1 source file; probe.py:26: note: Revealed type is "int"
$ python probe.py
A*B, A*C, A*D: str int int
f(A, B): str
$ pytest -n 4 -q -k testReverseOperatorOrderingForClassObjects mypy/test/testcheck.py
head: 1 passed checkexpr.py reverted to base: 1 failed (main:20: Expression is of type "int", not "str")
$ pytest -n 4 -q mypy/test/testcheck.py -k "check-classes or check-expressions or check-overloading or check-generics or check-protocols"
1502 passed, 4 skipped, 1 xfailed
Here or in a follow-up?
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Author
|
Thanks for the review! I addressed the type[A] / type[B] case in this PR in 29c567e, with regression tests for typed parameters and bounded type variables. I also corrected dispatch for operands sharing a metaclass. All CI checks are green. |
chrikrah
approved these changes
Nov 9, 2026
chrikrah
left a comment
There was a problem hiding this comment.
29c567e covers type[A] * type[B]; still mergeable from my side.
$ python -m mypy probe.py # a: type[A], b: type[B], sub: type[SubA], a: type[T bound A]
head 29c567e: a*b "str", sub*b "int", T-bound a*b "str" # runtime: str, int, str
checkexpr.py from 1903600: "int", "int", "int"
$ pytest -q -n 0 mypy/test/testcheck.py -k testReverseOperatorOrderingForClassObjects
head: 1 passed checkexpr.py from 1903600: 1 failed (main:25, 29, 31, 39)
$ pytest -q -n 0 mypy/test/testcheck.py -k "check-classes.test or check-expressions.test or check-generics.test"
1019 passed, 2 skipped, 1 xfailed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22377
Summary
Binary operators now use metaclasses to determine dispatch order for both direct class objects (
A * B) and class objects passed astype[A]/type[B]parameters.An overriding right-metaclass
__rmul__takes priority. Inherited or unrelated reflected methods keep left-method priority, and operands with the same metaclass do not try the reflected method.Evidence
intinstead ofstr. Additional cases failed for typed parameters, bounded type variables, and direct class operands sharing a metaclass.After: All regression cases pass.
check-classes,check-expressions,check-overloading,check-generics,check-protocols): 1,502 passed, 4 skipped, 1 xfailed.Merge Danger
Door: two-way
Blast Radius: inference
Affects binary-operator result typing for class objects and parameters annotated with
type[...].