diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2018-11-04 14:28:15 -0500 |
---|---|---|
committer | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2018-12-02 15:07:37 -0500 |
commit | f7a82245fcd61a9b477d250d94951f33dfe2f097 (patch) | |
tree | 342f3583a0730cbf2e30eed28b02c8ab9e4567bd /numpy/core/_methods.py | |
parent | b637e654706ae7efbf556091cb663197e2f28774 (diff) | |
download | numpy-f7a82245fcd61a9b477d250d94951f33dfe2f097.tar.gz |
MAINT: Allow subclasses in ndarray.__array_function__.
The Liskov substitution principle suggests it should.
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r-- | numpy/core/_methods.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index 8974f0ce1..baeab6383 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -161,11 +161,8 @@ def _array_function(self, func, types, args, kwargs): # TODO: rewrite this in C # Cannot handle items that have __array_function__ other than our own. for t in types: - if t is not mu.ndarray: - method = getattr(t, '__array_function__', _NDARRAY_ARRAY_FUNCTION) - if method is not _NDARRAY_ARRAY_FUNCTION: - return NotImplemented - - # Arguments contain no overrides, so we can safely call the - # overloaded function again. - return func(*args, **kwargs) + if not issubclass(t, mu.ndarray) and hasattr(t, '__array_function__'): + return NotImplemented + + # The regular implementation can handle this, so we call it directly. + return func.__wrapped__(*args, **kwargs) |