MCPcopy Index your code
hub / github.com/numpy/numpy / decorator

Function decorator

numpy/_core/overrides.py:145–175  ·  view source on GitHub ↗
(implementation)

Source from the content-addressed store, hash-verified

143
144 """
145 def decorator(implementation):
146 if verify:
147 if dispatcher is not None:
148 verify_matching_signatures(implementation, dispatcher)
149 else:
150 # Using __code__ directly similar to verify_matching_signature
151 co = implementation.__code__
152 last_arg = co.co_argcount + co.co_kwonlyargcount - 1
153 last_arg = co.co_varnames[last_arg]
154 if last_arg != "like" or co.co_kwonlyargcount == 0:
155 raise RuntimeError(
156 "__array_function__ expects `like=` to be the last "
157 "argument and a keyword-only argument. "
158 f"{implementation} does not seem to comply.")
159
160 if docs_from_dispatcher and dispatcher.__doc__ is not None:
161 doc = inspect.cleandoc(dispatcher.__doc__)
162 add_docstring(implementation, doc)
163
164 public_api = _ArrayFunctionDispatcher(dispatcher, implementation)
165 functools.update_wrapper(public_api, implementation)
166
167 if not verify and not getattr(implementation, "__text_signature__", None):
168 public_api.__signature__ = inspect.signature(dispatcher)
169
170 if module is not None:
171 public_api.__module__ = module
172
173 ARRAY_FUNCTIONS.add(public_api)
174
175 return public_api
176
177 return decorator
178

Callers

nothing calls this directly

Calls 3

array_function_dispatchFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…