diff options
author | Peter Andreas Entschev <peter@entschev.com> | 2020-11-16 10:09:15 -0800 |
---|---|---|
committer | Peter Andreas Entschev <peter@entschev.com> | 2020-11-16 10:09:15 -0800 |
commit | e0c9b265e171e92ee558c00712d1104e68f65c9b (patch) | |
tree | 675cd9d125ba452a81cee43b5418edfbf9e13164 /numpy/core/overrides.py | |
parent | 5da4a8e1835a11d5a03b715e9c0afe3bb96c883b (diff) | |
download | numpy-e0c9b265e171e92ee558c00712d1104e68f65c9b.tar.gz |
MAINT: Add array_function_dispatch_like helper
This helper is used to dispatch a Python function with the like=
argument or raise an error if the object passed doesn't implement the
__array_function__ protocol.
Diffstat (limited to 'numpy/core/overrides.py')
-rw-r--r-- | numpy/core/overrides.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/numpy/core/overrides.py b/numpy/core/overrides.py index c2b5fb7fa..31d1c1d74 100644 --- a/numpy/core/overrides.py +++ b/numpy/core/overrides.py @@ -34,6 +34,15 @@ def set_array_function_like_doc(public_api): return public_api +def array_function_dispatch_like(func, *args, **kwargs): + if not hasattr(kwargs['like'], '__array_function__'): + raise ValueError( + 'The `like` object must implement the `__array_function__` ' + 'protocol.' + ) + return func(*args, **kwargs) + + add_docstring( implement_array_function, """ |