(cls, func, skip_bound_arg=True,
                             globals=None, locals=None, eval_str=False)
return cls(parameters,
               return_annotation=annotations.get('return', _empty),
               __validate_parameters__=is_duck_function)
Private helper: constructs Signature for the given python function.
Private helper: constructs Signature for the given python function.
Private helper : constructs Signature for the given python function .
def _signature_from_function(cls, func, skip_bound_arg=True,
                             globals=None, locals=None, eval_str=False):
    """Private helper: constructs Signature for the given python function."""

    is_duck_function = False
    if not isfunction(func):
        if _signature_is_functionlike(func):
            is_duck_function = True
        else:
            # If it's not a pure Python function, and not a duck type
            # of pure function:
            raise TypeError('{!r} is not a Python function'.format(func))

    s = getattr(func, "__text_signature__", None)
    if s:
        return _signature_fromstr(cls, func, s, skip_bound_arg)

    Parameter = cls._parameter_cls

    # Parameter information.
    func_code = func.__code__
    pos_count = func_code.co_argcount
    arg_names = func_code.co_varnames
    posonly_count = func_code.co_posonlyargcount
    positional = arg_names[:pos_count]
    keyword_only_count = func_code.co_kwonlyargcount
    keyword_only = arg_names[pos_count:pos_count + keyword_only_count]
    annotations = get_annotations(func, globals=globals, locals=locals, eval_str=eval_str)
    defaults = func.__defaults__
    kwdefaults = func.__kwdefaults__

    if defaults:
        pos_default_count = len(defaults)
    else:
        pos_default_count = 0

    parameters = []

    non_default_count = pos_count - pos_default_count
    posonly_left = posonly_count

    # Non-keyword-only parameters w/o defaults.
    for name in positional[:non_default_count]:
        kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD
        annotation = annotations.get(name, _empty)
        parameters.append(Parameter(name, annotation=annotation,
                                    kind=kind))
        if posonly_left:
            posonly_left -= 1

    # ... w/ defaults.
    for offset, name in enumerate(positional[non_default_count:]):
        kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD
        annotation = annotations.get(name, _empty)
        parameters.append(Parameter(name, annotation=annotation,
                                    kind=kind,
                                    default=defaults[offset]))
        if posonly_left:
            posonly_left -= 1

    # *args
    if func_code.co_flags & CO_VARARGS:
        name = arg_names[pos_count + keyword_only_count]
        annotation = annotations.get(name, _empty)
        parameters.append(Parameter(name, annotation=annotation,
                                    kind=_VAR_POSITIONAL))

    # Keyword-only parameters.
    for name in keyword_only:
        default = _empty
        if kwdefaults is not None:
            default = kwdefaults.get(name, _empty)

        annotation = annotations.get(name, _empty)
        parameters.append(Parameter(name, annotation=annotation,
                                    kind=_KEYWORD_ONLY,
                                    default=default))
    # **kwargs
    if func_code.co_flags & CO_VARKEYWORDS:
        index = pos_count + keyword_only_count
        if func_code.co_flags & CO_VARARGS:
            index += 1

        name = arg_names[index]
        annotation = annotations.get(name, _empty)
        parameters.append(Parameter(name, annotation=annotation,
                                    kind=_VAR_KEYWORD))

    # Is 'func' is a pure Python function - don't validate the
    # parameters list (for correct order and defaults), it should be OK.
    return cls(parameters,
               return_annotation=annotations.get('return', _empty),
               __validate_parameters__=is_duck_function)
def _signature_from_function ( cls , func , skip_bound_arg = True , globals = None , locals = None , eval_str = False ) : is_duck_function = False if not isfunction ( func ) : if _signature_is_functionlike ( func ) : is_duck_function = True else : # If it's not a pure Python function, and not a duck type # of pure function: raise TypeError ( '{!r} is not a Python function' . format ( func ) ) s = getattr ( func , "__text_signature__" , None ) if s : return _signature_fromstr ( cls , func , s , skip_bound_arg ) Parameter = cls . _parameter_cls # Parameter information. func_code = func . __code__ pos_count = func_code . co_argcount arg_names = func_code . co_varnames posonly_count = func_code . co_posonlyargcount positional = arg_names [ : pos_count ] keyword_only_count = func_code . co_kwonlyargcount keyword_only = arg_names [ pos_count : pos_count + keyword_only_count ] annotations = get_annotations ( func , globals = globals , locals = locals , eval_str = eval_str ) defaults = func . __defaults__ kwdefaults = func . __kwdefaults__ if defaults : pos_default_count = len ( defaults ) else : pos_default_count = 0 parameters = [ ] non_default_count = pos_count - pos_default_count posonly_left = posonly_count # Non-keyword-only parameters w/o defaults. for name in positional [ : non_default_count ] : kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD annotation = annotations . get ( name , _empty ) parameters . append ( Parameter ( name , annotation = annotation , kind = kind ) ) if posonly_left : posonly_left -= 1 # ... w/ defaults. for offset , name in enumerate ( positional [ non_default_count : ] ) : kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD annotation = annotations . get ( name , _empty ) parameters . append ( Parameter ( name , annotation = annotation , kind = kind , default = defaults [ offset ] ) ) if posonly_left : posonly_left -= 1 # *args if func_code . co_flags & CO_VARARGS : name = arg_names [ pos_count + keyword_only_count ] annotation = annotations . get ( name , _empty ) parameters . append ( Parameter ( name , annotation = annotation , kind = _VAR_POSITIONAL ) ) # Keyword-only parameters. for name in keyword_only : default = _empty if kwdefaults is not None : default = kwdefaults . get ( name , _empty ) annotation = annotations . get ( name , _empty ) parameters . append ( Parameter ( name , annotation = annotation , kind = _KEYWORD_ONLY , default = default ) ) # **kwargs if func_code . co_flags & CO_VARKEYWORDS : index = pos_count + keyword_only_count if func_code . co_flags & CO_VARARGS : index += 1 name = arg_names [ index ] annotation = annotations . get ( name , _empty ) parameters . append ( Parameter ( name , annotation = annotation , kind = _VAR_KEYWORD ) ) # Is 'func' is a pure Python function - don't validate the # parameters list (for correct order and defaults), it should be OK. return cls ( parameters , return_annotation = annotations . get ( 'return' , _empty ) , __validate_parameters__ = is_duck_function )