MCPcopy
hub / github.com/dask/dask / takes_multiple_arguments

Function takes_multiple_arguments

dask/utils.py:653–697  ·  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

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

Callers 2

topkMethod · 0.90

Calls 1

getargspecFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…