From f7a82245fcd61a9b477d250d94951f33dfe2f097 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Sun, 4 Nov 2018 14:28:15 -0500 Subject: MAINT: Allow subclasses in ndarray.__array_function__. The Liskov substitution principle suggests it should. --- numpy/core/_methods.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'numpy/core/_methods.py') 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) -- cgit v1.2.1