from typing import Any, Union
import numpy as np
import numpy.typing as npt
ComplexArray = npt.NDArray[Union[np.floating[Any], np.complexfloating[Any, Any]]]
x: ComplexArray = np.array([1j])
print(x.real) # works great!
def f(x: ComplexArray) -> ComplexArray:
return x.real # fails?!
This one's a mystery because it works at the top level, but fails in the function.