-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
BUG: Usage of implicit reexports breaks using mypy with --no-implicit-reexport #21214
Description
Describe the issue:
The code example described below, when checked with mypy, reveals the type of the array and generates an error. If mypy is used with the option --no-implicit-reexport the code example described below does not reveal the type and does not generate any error. Adding the option --warn-unreachable shows that everything after numpy.cross is detected as unreachable.
As detected in python/mypy#12350 the issue is that an overload of numpy.cross uses _ArrayLikeBool_co but it is an implicit reexport. Due to that it resolves to Any and the following overload matches all calls to numpy.cross and the calls resolve to NoReturn.
Lines 461 to 469 in 71e7620
| @overload | |
| def cross( | |
| a: _ArrayLikeBool_co, | |
| b: _ArrayLikeBool_co, | |
| axisa: int = ..., | |
| axisb: int = ..., | |
| axisc: int = ..., | |
| axis: None | int = ..., | |
| ) -> NoReturn: ... |
I see two options to resolve this issue:
- Replacing imports from
numpy.typingto the package where they are actually defined, likefrom numpy.typing._array_like import _ArrayLikeBool_co - Explicitly reexport private types from
numpy.typingas well.
Reproduce the code example:
import numpy
from numpy.typing import ArrayLike
def test_method() -> None:
value: ArrayLike = numpy.cross(numpy.array([1, 2, 3]), numpy.array([4, 5, 6]))
reveal_type(value)
broken: int = 'test'Error message:
No response
NumPy/Python version information:
1.22.3 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]