Verify that a dispatcher function has the right signature.
(implementation, dispatcher)
| 81 | |
| 82 | |
| 83 | def 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 | |
| 105 | def array_function_dispatch(dispatcher=None, module=None, verify=True, |