MCPcopy Create free account
hub / github.com/numpy/numpy / verify_matching_signatures

Function verify_matching_signatures

numpy/core/overrides.py:83–102  ·  view source on GitHub ↗

Verify that a dispatcher function has the right signature.

(implementation, dispatcher)

Source from the content-addressed store, hash-verified

81
82
83def verify_matching_signatures(implementation, dispatcher):
84 """Verify that a dispatcher function has the right signature."""
85 implementation_spec = ArgSpec(*getargspec(implementation))
86 dispatcher_spec = ArgSpec(*getargspec(dispatcher))
87
88 if (implementation_spec.args != dispatcher_spec.args or
89 implementation_spec.varargs != dispatcher_spec.varargs or
90 implementation_spec.keywords != dispatcher_spec.keywords or
91 (bool(implementation_spec.defaults) !=
92 bool(dispatcher_spec.defaults)) or
93 (implementation_spec.defaults is not None and
94 len(implementation_spec.defaults) !=
95 len(dispatcher_spec.defaults))):
96 raise RuntimeError('implementation and dispatcher for %s have '
97 'different function signatures' % implementation)
98
99 if implementation_spec.defaults is not None:
100 if dispatcher_spec.defaults != (None,) * len(dispatcher_spec.defaults):
101 raise RuntimeError('dispatcher functions can only use None for '
102 'default argument values')
103
104
105def array_function_dispatch(dispatcher=None, module=None, verify=True,

Callers 2

decoratorFunction · 0.85

Calls 1

getargspecFunction · 0.85

Tested by 1