Function signature objects for callables

Back port of Python 3.3's function signature tools from the inspect module, modified to be compatible with Python 2.7 and 3.2+.

class core.funcsigs.BoundArguments(signature, arguments)[source]

Bases: object

Result of Signature.bind call. Holds the mapping of arguments to the function's parameters.

Has the following public attributes:

  • arguments : OrderedDict

    An ordered mutable mapping of parameters' names to arguments' values. Does not contain arguments' default values.

  • signature : Signature

    The Signature object that created this instance.

  • args : tuple

    Tuple of positional arguments values.

  • kwargs : dict

    Dict of keyword arguments values.

args[source]
kwargs[source]
signature[source]
class core.funcsigs.Parameter(name, kind, default=<class 'core.funcsigs._empty'>, annotation=<class 'core.funcsigs._empty'>, _partial_kwarg=False)[source]

Bases: object

Represents a parameter in a function signature.

Has the following public attributes:

  • name : str

    The name of the parameter as a string.

  • default : object

    The default value for the parameter if specified. If the parameter has no default value, this attribute is not set.

  • annotation

    The annotation for the parameter if specified. If the parameter has no annotation, this attribute is not set.

  • kind : str

    Describes how argument values are bound to the parameter. Possible values: Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD, Parameter.VAR_POSITIONAL, Parameter.KEYWORD_ONLY, Parameter.VAR_KEYWORD.

empty

alias of _empty

replace(name=<class 'core.funcsigs._void'>, kind=<class 'core.funcsigs._void'>, annotation=<class 'core.funcsigs._void'>, default=<class 'core.funcsigs._void'>, _partial_kwarg=<class 'core.funcsigs._void'>)[source]

Creates a customized copy of the Parameter.

KEYWORD_ONLY = <_ParameterKind: 'KEYWORD_ONLY'>
POSITIONAL_ONLY = <_ParameterKind: 'POSITIONAL_ONLY'>
POSITIONAL_OR_KEYWORD = <_ParameterKind: 'POSITIONAL_OR_KEYWORD'>
VAR_KEYWORD = <_ParameterKind: 'VAR_KEYWORD'>
VAR_POSITIONAL = <_ParameterKind: 'VAR_POSITIONAL'>
annotation[source]
default[source]
kind[source]
name[source]
class core.funcsigs.Signature(parameters=None, return_annotation=<class 'core.funcsigs._empty'>, __validate_parameters__=True)[source]

Bases: object

A Signature object represents the overall signature of a function. It stores a Parameter object for each parameter accepted by the function, as well as information specific to the function itself.

A Signature object has the following public attributes and methods:

  • parameters : OrderedDict

    An ordered mapping of parameters' names to the corresponding Parameter objects (keyword-only arguments are in the same order as listed in code.co_varnames).

  • return_annotation : object

    The annotation for the return type of the function if specified. If the function has no annotation for its return type, this attribute is not set.

  • bind(*args, **kwargs) -> BoundArguments

    Creates a mapping from positional and keyword arguments to parameters.

  • bind_partial(*args, **kwargs) -> BoundArguments

    Creates a partial mapping from positional and keyword arguments to parameters (simulating 'functools.partial' behavior.)

empty

alias of _empty

bind(*args, **kwargs)[source]

Get a BoundArguments object, that maps the passed args and kwargs to the function's signature. Raises TypeError if the passed arguments can not be bound.

bind_partial(*args, **kwargs)[source]

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.

classmethod from_function(func)[source]

Constructs Signature for the given python function

replace(parameters=<class 'core.funcsigs._void'>, return_annotation=<class 'core.funcsigs._void'>)[source]

Creates a customized copy of the Signature. Pass 'parameters' and/or 'return_annotation' arguments to override them in the new copy.

parameters[source]
return_annotation[source]
core.funcsigs.signature(obj)[source]

Get a signature object for the passed callable.

Previous topic

<no title>

Next topic

<no title>

This Page