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/overrides.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/overrides.py')
-rw-r--r-- | numpy/core/overrides.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/numpy/core/overrides.py b/numpy/core/overrides.py index 1cc1ff8d8..8bdbe1708 100644 --- a/numpy/core/overrides.py +++ b/numpy/core/overrides.py @@ -62,16 +62,6 @@ def get_overloaded_types_and_args(relevant_args): overloaded_types = [arg_type] overloaded_args = [arg] - # Short-cut for the common case of only ndarray. - if overloaded_types == _NDARRAY_ONLY: - return overloaded_types, [] - - # Special handling for ndarray.__array_function__ - overloaded_args = [ - arg for arg in overloaded_args - if type(arg).__array_function__ is not _NDARRAY_ARRAY_FUNCTION - ] - return overloaded_types, overloaded_args @@ -106,7 +96,11 @@ def array_function_implementation_or_override( """ # Check for __array_function__ methods. types, overloaded_args = get_overloaded_types_and_args(relevant_args) - if not overloaded_args: + # Short-cut for common cases: no overload or only ndarray overload + # (directly or with subclasses that do not override __array_function__). + if (not overloaded_args or types == _NDARRAY_ONLY or + all(type(arg).__array_function__ is _NDARRAY_ARRAY_FUNCTION + for arg in overloaded_args)): return implementation(*args, **kwargs) # Call overrides |