import inspect


def _num_required_args(func):
    """ Number of args for func

        >>> def foo(a, b, c=None):
        ... return a + b + c

        >>> _num_required_args(foo)
        2

        >>> def bar(*args):
        ... return sum(args)

        >>> print(_num_required_args(bar))
        None

        borrowed from: https://github.com/pytoolz/toolz
    """
    try:
        spec = inspect.getfullargspec(func)
        if spec.varargs:
            return None
        num_defaults = len(spec.defaults) if spec.defaults else 0
        return len(spec.args) - num_defaults
    except TypeError:
        return None