Get a BoundArguments object, that partially maps the
        passed `args` and `kwargs` to the function's signature.
        Raises `TypeError` if the passed arguments can not be bound.
490457
def bind_partial(self, *args, **kwargs):
        
        return self._bind(args, kwargs, partial=True)
475897
def _parse_args(args, cls):
    
    
    d = _create_djset(args, cls)
    
    key_value_pair = args.get('<key>=<value>')
    key = args.get('<key>')
    func = None
    if args.get('add') and key_value_pair:
        fargs = tuple(args.get('<key>=<value>').split('='))
        if fargs[1]:
            func = d.set
    elif args.get('remove') and key:
        func = d.remove
        fargs = (args.get('<key>'),)
    kwargs = {'glob': args.get('--global')}
    if func:
        return func, fargs, kwargs
    else:
        return None, None, None
887355
def with_args_validator(self, matching_function):
        
        self.args = None
        self.kwargs = None
        self._custom_matcher = matching_function
        return self
1133749
def signature(obj):
    ''''''

    if not callable(obj):
        raise TypeError('{0!r} is not a callable object'.format(obj))

    if isinstance(obj, types.MethodType):
        sig = signature(obj.__func__)
        if obj.__self__ is None:
            # Unbound method: the first parameter becomes positional-only
            if sig.parameters:
                first = sig.parameters.values()[0].replace(
                    kind=_POSITIONAL_ONLY)
                return sig.replace(
                    parameters=(first,) + tuple(sig.parameters.values())[1:])
            else:
                return sig
        else:
            # In this case we skip the first parameter of the underlying
            # function (usually `self` or `cls`).
            return sig.replace(parameters=tuple(sig.parameters.values())[1:])

    try:
        sig = obj.__signature__
    except AttributeError:
        pass
    else:
        if sig is not None:
            return sig

    try:
        # Was this function wrapped by a decorator?
        wrapped = obj.__wrapped__
    except AttributeError:
        pass
    else:
        return signature(wrapped)

    if isinstance(obj, types.FunctionType):
        return Signature.from_function(obj)

    if isinstance(obj, functools.partial):
        sig = signature(obj.func)

        new_params = OrderedDict(sig.parameters.items())

        partial_args = obj.args or ()
        partial_keywords = obj.keywords or {}
        try:
            ba = sig.bind_partial(*partial_args, **partial_keywords)
        except TypeError:
            msg = 'partial object {0!r} has incorrect arguments'.format(obj)
            raise ValueError(msg)

        for arg_name, arg_value in ba.arguments.items():
            param = new_params[arg_name]
            if arg_name in partial_keywords:
                # We set a new default value, because the following code
                # is correct:
                #
                #   >>> def foo(a): print(a)
                #   >>> print(partial(partial(foo, a=10), a=20)())
                #   20
                #   >>> print(partial(partial(foo, a=10), a=20)(a=30))
                #   30
                #
                # So, with 'partial' objects, passing a keyword argument is
                # like setting a new default value for the corresponding
                # parameter
                #
                # We also mark this parameter with '_partial_kwarg'
                # flag.  Later, in '_bind', the 'default' value of this
                # parameter will be added to 'kwargs', to simulate
                # the 'functools.partial' real call.
                new_params[arg_name] = param.replace(default=arg_value,
                                                     _partial_kwarg=True)

            elif (param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL)
                  and not param._partial_kwarg):
                new_params.pop(arg_name)

        return sig.replace(parameters=new_params.values())

    sig = None
    if isinstance(obj, type):
        # obj is a class or a metaclass

        # First, let's see if it has an overloaded __call__ defined
        # in its metaclass
        call = _get_user_defined_method(type(obj), '__call__')
        if call is not None:
            sig = signature(call)
        else:
            # Now we check if the 'obj' class has a '__new__' method
            new = _get_user_defined_method(obj, '__new__')
            if new is not None:
                sig = signature(new)
            else:
                # Finally, we should have at least __init__ implemented
                init = _get_user_defined_method(obj, '__init__')
                if init is not None:
                    sig = signature(init)
    elif not isinstance(obj, _NonUserDefinedCallables):
        # An object with __call__
        # We also check that the 'obj' is not an instance of
        # _WrapperDescriptor or _MethodWrapper to avoid
        # infinite recursion (and even potential segfault)
        call = _get_user_defined_method(type(obj), '__call__', 'im_func')
        if call is not None:
            sig = signature(call)

    if sig is not None:
        # For classes and objects we skip the first parameter of their
        # __call__, __new__, or __init__ methods
        return sig.replace(parameters=tuple(sig.parameters.values())[1:])

    if isinstance(obj, types.BuiltinFunctionType):
        # Raise a nicer error message for builtins
        msg = 'no signature found for builtin function {0!r}'.format(obj)
        raise ValueError(msg)

    raise ValueError(
        'callable {0!r} is not supported by signature'.format(obj))
235282
def _parse_arguments():
        
        parser = get_base_arguments(get_parser())
        parser = get_tc_arguments(parser)
        args, unknown = parser.parse_known_args()
        return args, unknown
463945
def get_args(method_or_func):
    """"""
    try:
        # Python 3.0+
        args = list(inspect.signature(method_or_func).parameters.keys())
    except AttributeError:
        # Python 2.7
        args = inspect.getargspec(method_or_func).args
    return args
577000
def get_func_args(func):
    
    if isinstance(func, functools.partial):
        return _signature(func.func)
    if inspect.isfunction(func) or inspect.ismethod(func):
        return _signature(func)
    # Callable class
    return _signature(func.__call__)
799603
def optional_argument_decorator(_decorator):
    """"""

    @functools.wraps(_decorator)
    def inner_decorator_make(*args, **kwargs):
        if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
            func = args[0]
            args = tuple()
            kwargs = dict()
        else:
            func = None

        decorator = _decorator(*args, **kwargs)

        if func:
            return decorator(func)
        else:
            return decorator

    return inner_decorator_make
683842
def _validate_func_args(func, kwargs):
    """"""

    args, varargs, varkw, defaults = inspect.getargspec(func)
    if set(kwargs.keys()) != set(args[1:]): # chop off self
        raise TypeError("decorator kwargs do not match %s()'s kwargs"
                        % func.__name__)
719750
def normalize_args(f, *args, **kwargs):
    
    callargs = inspect.getcallargs(f, *args, **kwargs)
    original_callargs = callargs.copy()
    try:
        argspec = inspect.getargspec(f)
    except ValueError:
        argspec = inspect.getfullargspec(f)
    else:
        argspec = fullargspec_from_argspec(argspec)

    if hasattr(argspec, 'varkw'):
        if argspec.varkw:
            kwargs = callargs.pop(argspec.varkw, {})
            callargs.update(kwargs)

    if argspec.varargs:
        varargs = callargs.pop(argspec.varargs, ())
    else:
        varargs = ()

    # now callargs is all keywords

    return NormalizedArgs(varargs=varargs,
                          normargs=callargs,
                          callargs=original_callargs)
1043819
def get_param_arg(param, idx, klass, arg, attr='id'):
    """"""
    if isinstance(arg, klass):
        return getattr(arg, attr)
    elif isinstance(arg, (int, str)):
        return arg
    else:
        raise TypeError(
            "%s[%d] must be int, str, or %s, not %s" % (
                param, idx, klass.__name__, type(arg).__name__))
56411
def get_kwargs(**kwargs):
        
        d = dict()
        for k, v in kwargs.iteritems():
            if v is not NOTSET:
                d[k] = v
        return d
368144
def optional_args_func(func) -> callable:
    
    if getattr(func, '_optional_args_func', False):
        return func

    is_generator = inspect.isgeneratorfunction(func)
    func_sig = inspect.signature(func)
    expects_nothing = not func_sig.parameters

    if is_generator:
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if expects_nothing:
                yield from func()
            else:
                bound_arguments = func_sig.bind(*args, **{k: v for k, v in kwargs.items() if k in func_sig.parameters})
                yield from func(*bound_arguments.args, **bound_arguments.kwargs)
    else:
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if expects_nothing:
                return func()
            else:
                bound_arguments = func_sig.bind(*args, **{k: v for k, v in kwargs.items() if k in func_sig.parameters})
                return func(*bound_arguments.args, **bound_arguments.kwargs)

    # Mark it so that we don't double wrap our own
    setattr(wrapped, '_optional_args_func', True)

    return wrapped
102518
def get_all_args(fn) -> list:
    
    sig = inspect.signature(fn)
    return list(sig.parameters)
863773
def function_arguments(func):
    
    if getattr(inspect, 'signature', None) is None:
        return list(inspect.getargspec(func).args)
    else:
        return list(inspect.signature(func).parameters.keys())
507767
def check_arguments(c: typing.Callable,
                    hints: typing.Mapping[str, typing.Optional[type]],
                    *args, **kwargs) -> None:
    
    signature = inspect.signature(c)
    bound = signature.bind(*args, **kwargs)
    for argument_name, value in bound.arguments.items():
        try:
            type_hint = hints[argument_name]
        except KeyError:
            continue
        actual_type, correct = check_type(value, type_hint)
        if not correct:
            raise TypeError(
                'Incorrect type `{}`, expected `{}` for `{}`'.format(
                    actual_type, type_hint, argument_name
                )
            )
1280373
def generate_accepted_kwargs(function, *named_arguments):
    
    if hasattr(function, '__code__') and takes_kwargs(function):
        function_takes_kwargs = True
        function_takes_arguments = []
    else:
        function_takes_kwargs = False
        function_takes_arguments = takes_arguments(function, *named_arguments)

    def accepted_kwargs(kwargs):
        if function_takes_kwargs:
            return kwargs
        elif function_takes_arguments:
            return {key: value for key, value in kwargs.items() if key in function_takes_arguments}
        return {}
    return accepted_kwargs