Skip to content

pow(complex(…), <value>, <value>) and pow(float(…), <value>, <value>) should produce type errors #6303

Closed as not planned
@posita

Description

@posita

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 floats 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 ints:

>>> 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions