You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mypy signals error with Protocol and __rpow__ method with three arguments #10786
% mypy --version
mypy 0.910
% mypy --config-file=/dev/null test_case.py
/dev/null: No [mypy] section in config file
test_case.py:15: error: Invalid signature "def (test_case.PowableProto, test_case.PowableProto, test_case.PowableProto) -> test_case.PowableProto"
Found 1 error in 1 file (checked 1 source file)
Expected vs. Actual Behavior
I would expect at least consistent behavior among the overridden methods. This only crops up with __rpow__ for some reason. (I have tested many others.)
Your Environment
Mypy version used: 0.910
Mypy command-line flags: --config-file=/dev/null (i.e., force default configuration)
Mypy configuration options from mypy.ini (and other config files): N/A
Python version used: Python 3.9.6 (from python --version)
Operating system and version: Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 (from uname -v)
changed the title [-]Protocol doesn't like second @overload-ed __rpow__ method—and *only* the second @overload-ed __rpow__ method[/-][+]Mypy signals error with Protocol and __rpow__ method with three arguments[/+]on Jul 8, 2021
I don't think it is related to recursive types. Mypy has strong requirements for Python special methods, and FWIW I think it is fine to relax those for protocols, probably an easy fix.
I think the error is correct in this case, isn't it? The three argument version of __pow__ is called when the built-in pow function is called, but the python docs explicitly mention that __rpow__ does not use the three argument version. From https://docs.python.org/3/reference/datamodel.html
Note that ternary pow() will not try calling rpow() (the coercion rules would become too complicated).
Activity
posita commentedon Jul 8, 2021
Actually, scratch that. Here's a simpler test case that still breaks on
__rpow__(and only on__rpow__):This (in the style of using ellipses for default arguments in stub files) works, though:
The callout of
__rpow__still seems…weird. 🤨[-]Protocol doesn't like second @overload-ed __rpow__ method—and *only* the second @overload-ed __rpow__ method[/-][+]Mypy signals error with Protocol and __rpow__ method with three arguments[/+]ilevkivskyi commentedon Nov 16, 2022
I don't think it is related to recursive types. Mypy has strong requirements for Python special methods, and FWIW I think it is fine to relax those for protocols, probably an easy fix.
fix python#10786
Cnoor0171 commentedon Dec 5, 2023
I think the error is correct in this case, isn't it? The three argument version of
__pow__is called when the built-inpowfunction is called, but the python docs explicitly mention that__rpow__does not use the three argument version. From https://docs.python.org/3/reference/datamodel.htmljorenham commentedon Jun 29, 2026
Since Python 3.14, the 3-argument
__rpow__for ternarypowis supported: python/cpython#130251. The 3.14 relnotes also mention this: https://docs.python.org/3/whatsnew/3.14.html#built-insposita commentedon Jun 30, 2026
Hmmm...then maybe @Cnoor0171 was right with #10786 (comment) ? My first two test cases still produce errors:
Sounds like this can be closed as either fixed or as-designed?
Allow a three-argument __rpow__ overload item
Allow a three-argument __rpow__ overload item