True if the object is a callable that takes no arguments.
(obj)
| 64 | |
| 65 | |
| 66 | def is_simple_callable(obj): |
| 67 | """ |
| 68 | True if the object is a callable that takes no arguments. |
| 69 | """ |
| 70 | if not callable(obj): |
| 71 | return False |
| 72 | |
| 73 | # Bail early since we cannot inspect built-in function signatures. |
| 74 | if inspect.isbuiltin(obj): |
| 75 | raise BuiltinSignatureError( |
| 76 | 'Built-in function signatures are not inspectable. ' |
| 77 | 'Wrap the function call in a simple, pure Python function.') |
| 78 | |
| 79 | if not (inspect.isfunction(obj) or inspect.ismethod(obj) or isinstance(obj, functools.partial)): |
| 80 | return False |
| 81 | |
| 82 | sig = inspect.signature(obj) |
| 83 | params = sig.parameters.values() |
| 84 | return all( |
| 85 | param.kind == param.VAR_POSITIONAL or |
| 86 | param.kind == param.VAR_KEYWORD or |
| 87 | param.default != param.empty |
| 88 | for param in params |
| 89 | ) |
| 90 | |
| 91 | |
| 92 | def get_attribute(instance, attrs): |