MCPcopy Create free account
hub / github.com/dask/dask / takes_multiple_arguments

Function takes_multiple_arguments

dask/utils.py:652–696  ·  view source on GitHub ↗

Does this function take multiple arguments? >>> def f(x, y): pass >>> takes_multiple_arguments(f) True >>> def f(x): pass >>> takes_multiple_arguments(f) False >>> def f(x, y=None): pass >>> takes_multiple_arguments(f) False >>> def f(*args): pass >>>

(func, varargs=True)

Source from the content-addressed store, hash-verified

650
651
652def takes_multiple_arguments(func, varargs=True):
653 """Does this function take multiple arguments?
654
655 >>> def f(x, y): pass
656 >>> takes_multiple_arguments(f)
657 True
658
659 >>> def f(x): pass
660 >>> takes_multiple_arguments(f)
661 False
662
663 >>> def f(x, y=None): pass
664 >>> takes_multiple_arguments(f)
665 False
666
667 >>> def f(*args): pass
668 >>> takes_multiple_arguments(f)
669 True
670
671 >>> class Thing:
672 ... def __init__(self, a): pass
673 >>> takes_multiple_arguments(Thing)
674 False
675
676 """
677 if func in ONE_ARITY_BUILTINS:
678 return False
679 elif func in MULTI_ARITY_BUILTINS:
680 return True
681
682 try:
683 spec = getargspec(func)
684 except Exception:
685 return False
686
687 try:
688 is_constructor = spec.args[0] == "self" and isinstance(func, type)
689 except Exception:
690 is_constructor = False
691
692 if varargs and spec.varargs:
693 return True
694
695 ndefaults = 0 if spec.defaults is None else len(spec.defaults)
696 return len(spec.args) - ndefaults - is_constructor > 1
697
698
699def get_named_args(func) -> list[str]:

Callers 2

topkMethod · 0.90

Calls 1

getargspecFunction · 0.85

Tested by 1