Open jamesohortle opened 5 years ago
The root of the problem is that mypy incorrectly infers the type of multiplying Point
by a float. Here's a shorter example:
from typing import Any
C: Any
class D(C):
pass
reveal_type(0.5 * D()) # float, but should be Any
As a workaround, you can try installing stubs for numpy (https://github.com/numpy/numpy-stubs).
It looks like #8019 didn't actually fix this issue, at least Jukka's simple example above still fails. It accidentally passes in tests (see testOpWithInheritedFromAny
) because in builtins fixtures float
doesn't have __add__()
. I am going to mark it xfail
in https://github.com/python/mypy/pull/14077 (since I need that __add__()
that actually present in real builtins stubs, for my tests).
cc @TH3CHARLie @msullivan
Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues
Please provide more information to help us understand the issue:
Bug.
Mypy gives the errors below:
In the lambda in
average_position()
, mypy incorrectly (?) determines the type asCallable[[Point], float]
, while using the NumPy functionnp.multiply()
(which does the same thing) gives no error. Both functions output the same correct value.What is the behavior/output you expect? There should be no error.
What are the versions of mypy and Python you are using? Do you see the same issue after installing mypy from Git master?
I am unsure if this is actually an error, or if I've done something wrong somewhere, but both functions run and output correctly.