diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2021-08-10 16:01:27 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2021-08-25 16:32:26 -0500 |
commit | 8b885046e1e1f11a76f6acdf9a5426280cf97bac (patch) | |
tree | 68bedff49d458bda6c69700892d07b369a0bd637 /numpy/core/overrides.py | |
parent | 3712815c3209c4769ccad60de110f2bd8f3763ec (diff) | |
download | numpy-8b885046e1e1f11a76f6acdf9a5426280cf97bac.tar.gz |
remove import time compile
Diffstat (limited to 'numpy/core/overrides.py')
-rw-r--r-- | numpy/core/overrides.py | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/numpy/core/overrides.py b/numpy/core/overrides.py index 70085d896..d15980f7f 100644 --- a/numpy/core/overrides.py +++ b/numpy/core/overrides.py @@ -126,18 +126,6 @@ def set_module(module): return decorator - -# Call textwrap.dedent here instead of in the function so as to avoid -# calling dedent multiple times on the same text -_wrapped_func_source = textwrap.dedent(""" - @functools.wraps(implementation) - def {name}(*args, **kwargs): - relevant_args = dispatcher(*args, **kwargs) - return implement_array_function( - implementation, {name}, relevant_args, args, kwargs) - """) - - def array_function_dispatch(dispatcher, module=None, verify=True, docs_from_dispatcher=False): """Decorator for adding dispatch with the __array_function__ protocol. @@ -187,25 +175,15 @@ def array_function_dispatch(dispatcher, module=None, verify=True, if docs_from_dispatcher: add_docstring(implementation, dispatcher.__doc__) - # Equivalently, we could define this function directly instead of using - # exec. This version has the advantage of giving the helper function a - # more interpettable name. Otherwise, the original function does not - # show up at all in many cases, e.g., if it's written in C or if the - # dispatcher gets an invalid keyword argument. - source = _wrapped_func_source.format(name=implementation.__name__) - - source_object = compile( - source, filename='<__array_function__ internals>', mode='exec') - scope = { - 'implementation': implementation, - 'dispatcher': dispatcher, - 'functools': functools, - 'implement_array_function': implement_array_function, - } - exec(source_object, scope) - - public_api = scope[implementation.__name__] + @functools.wraps(implementation) + def public_api(*args, **kwargs): + relevant_args = dispatcher(*args, **kwargs) + return implement_array_function( + implementation, public_api, relevant_args, args, kwargs) + public_api.__code__ = public_api.__code__.replace( + co_name=implementation.__name__, + co_filename='<string>') if module is not None: public_api.__module__ = module |