(f: TCallable)
| 117 | |
| 118 | |
| 119 | def get_arity(f: TCallable) -> int: |
| 120 | |
| 121 | if isbuiltin(f): |
| 122 | rv = 0 # assume 0 arity for builtins; they cannot be introspected |
| 123 | else: |
| 124 | # NB: this is not understood by mypy |
| 125 | n_defaults = len(f.__defaults__) if f.__defaults__ else 0 |
| 126 | rv = f.__code__.co_argcount - n_defaults |
| 127 | |
| 128 | return rv |
| 129 | |
| 130 | |
| 131 | K = TypeVar("K") |