(func)
return args, kwargs
Returns (args, kwargs) tuple for a function
    >>> import re
    >>> get_spec(re.match)
    (['pattern', 'string'], {'flags': 0})

    >>> class Test:
    ...     def __call__(self, val):
    ...         pass
    ...     def method(self, val, flags=0):
    ...         pass

    >>> get_spec(Test)
    (['self', 'val'], {})

    >>> get_spec(Test.method)
    (['self', 'val'], {'flags': 0})

    >>> get_spec(Test().method)
    (['self', 'val'], {'flags': 0})
Returns (args, kwargs) tuple for a function
    >>> import re
    >>> get_spec(re.match)
    (['pattern', 'string'], {'flags': 0})
Returns ( args kwargs ) tuple for a function >>> import re >>> get_spec ( re . match ) ( [ pattern string ] { flags : 0 } )
def get_spec(func):
    """Returns (args, kwargs) tuple for a function
    >>> import re
    >>> get_spec(re.match)
    (['pattern', 'string'], {'flags': 0})

    >>> class Test:
    ...     def __call__(self, val):
    ...         pass
    ...     def method(self, val, flags=0):
    ...         pass

    >>> get_spec(Test)
    (['self', 'val'], {})

    >>> get_spec(Test.method)
    (['self', 'val'], {'flags': 0})

    >>> get_spec(Test().method)
    (['self', 'val'], {'flags': 0})
    """

    if inspect.isfunction(func) or inspect.ismethod(func):
        spec = _getargspec_py23(func)
    elif hasattr(func, '__call__'):
        spec = _getargspec_py23(func.__call__)
    else:
        raise TypeError(f'{type(func)} is not callable')

    defaults = spec.defaults or []

    firstdefault = len(spec.args) - len(defaults)
    args = spec.args[:firstdefault]
    kwargs = dict(zip(spec.args[firstdefault:], defaults))
    return args, kwargs
def get_spec ( func ) : if inspect . isfunction ( func ) or inspect . ismethod ( func ) : spec = _getargspec_py23 ( func ) elif hasattr ( func , '__call__' ) : spec = _getargspec_py23 ( func . __call__ ) else : raise TypeError ( f'{type(func)} is not callable' ) defaults = spec . defaults or [ ] firstdefault = len ( spec . args ) - len ( defaults ) args = spec . args [ : firstdefault ] kwargs = dict ( zip ( spec . args [ firstdefault : ] , defaults ) ) return args , kwargs