On Mon, Jun 4, 2018 at 5:39 AM Matthew Harrigan <harrigan.matt...@gmail.com>
wrote:

> Should there be discussion of typing (pep-484) or abstract base classes in
> this nep?  Are there any requirements on the result returned by
> __array_function__?
>

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 [1] and
overloads [2], I think this could just work, e.g.,

@overload
def func(array: np.ndarray) -> np.ndarray: ...
@overload
def func(array: ImplementsArrayFunction) -> Any: ...

[1] https://www.python.org/dev/peps/pep-0544/
[2] https://github.com/python/typing/issues/253#issuecomment-389262904
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to