I was trying to perform a type check for a function that accepts both float or np.ndarray[np.float].
Mypy does not complain of any of the following implementations:
from typing import Union
import numpy as np
import numpy.typing as npt
_T = Union[float, npt.NDArray[np.float64]]
def func(a: _T) -> _T:
return a
a = np.array([1])
func(a)
b = np.array([True])
func(b)
c = np.array([""])
func(c)
Shouldn't mypy complain about the dtype being different from np.float64?
I already found workarounds for the solution of my problem. But I would like to know why the above code does not work.