[Numpy-discussion] NEP: Dispatch Mechanism for NumPy’s high level API
shoyer at gmail.com
Tue Jun 5 14:34:18 EDT 2018
On Mon, Jun 4, 2018 at 5:39 AM Matthew Harrigan <harrigan.matthew at gmail.com>
> Should there be discussion of typing (pep-484) or abstract base classes in
> this nep? Are there any requirements on the result returned by
This is a good question that should be addressed in the NEP. Currently, we
impose no limitations on the types returned by __array_function__ (or
__array_ufunc__, for that matter). Given the complexity of potential
__array_function__ implementations, I think this would be hard/impossible
to do in general.
I think the best case scenario we could hope for is that type checkers
would identify that result of NumPy functions as:
- numpy.ndarray if all inputs are numpy.ndarray objects
- Any if any non-numpy.ndarray inputs implement the __array_function__
Based on my understanding of proposed rules for typing protocols  and
overloads , I think this could just work, e.g.,
def func(array: np.ndarray) -> np.ndarray: ...
def func(array: ImplementsArrayFunction) -> Any: ...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion