Open
Description
Proposed new feature or change:
For numpy.typing.NDArray
, the argument needs to be a subtype of numpy.generic
. However, this leads to problem since we can no longer specify concrete types for object
-arrays, for example, mypy
raises [type-var]
for this code:
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.axes import Axes
from numpy.typing import NDArray
axes: NDArray[Axes] # ✘ mypy: raises type-var
fig: Figure
fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)
for ax in axes.flat:
reveal_type(axes) # Axes if the previous error is ignored, else ndarray
ax.set_title("A subplot")
For NDArray
of dtype np.object_
, it should somehow wrap the given type. One approach could be to make np.object_
generic and change methods overloads so that for object-type, it generally returns the wrapped type.