Closed as not planned
Closed as not planned
Description
complex
's versions of __pow__
and __rpow__
invite the third modulo argument. That means that the following validates, when it shouldn't:
This applies to float
s as well.
pow(complex(1), 2, 2) # no type error?
pow(float(1), 2, 2) # still no type error?
These are guaranteed to fail at runtime, even if the first arguments are losslessly convertible to int
s:
>>> pow(complex(1), 2, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: complex modulo
>>> pow(float(1), 2, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: pow() 3rd argument not allowed unless all arguments are integers
I can't find an issue tracking this, and I don't think this is fixed by #6287.
As an aside, this "works" (in the sense it properly generates some error, but not what I would expect):
from numbers import Complex
my_complex: Complex = complex(1) # type: ignore [assignment] # see 3186
pow(my_complex, 2, 2) # No overload variant of "pow" matches argument types "Complex", "int", "int"
That second error might just be some variation on python/mypy#3186, however?