Module: utils.signatures¶
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+.
3 Classes¶
-
class
IPython.utils.signatures.Parameter(name, kind, default=<class 'IPython.utils.signatures._empty'>, annotation=<class 'IPython.utils.signatures._empty'>, _partial_kwarg=False)¶ Bases:
objectRepresents 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.
-
__init__(name, kind, default=<class 'IPython.utils.signatures._empty'>, annotation=<class 'IPython.utils.signatures._empty'>, _partial_kwarg=False)¶
-
replace(name=<class 'IPython.utils.signatures._void'>, kind=<class 'IPython.utils.signatures._void'>, annotation=<class 'IPython.utils.signatures._void'>, default=<class 'IPython.utils.signatures._void'>, _partial_kwarg=<class 'IPython.utils.signatures._void'>)¶ Creates a customized copy of the Parameter.
-
class
IPython.utils.signatures.BoundArguments(signature, arguments)¶ Bases:
objectResult of
Signature.bind()call. Holds the mapping of arguments to the function’s parameters.Has the following public attributes:
- arguments :
- An ordered mutable mapping of parameters’ names to arguments’ values. Does not contain arguments’ default values.
- signature :
- The Signature object that created this instance.
- args : tuple
- Tuple of positional arguments values.
- kwargs : dict
- Dict of keyword arguments values.
collections.OrderedDictSignature-
__init__(signature, arguments)¶
-
class
IPython.utils.signatures.Signature(parameters=None, return_annotation=<class 'IPython.utils.signatures._empty'>, __validate_parameters__=True)¶ Bases:
objectA 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:
- parameters :
- 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
- 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.
collections.OrderedDict-
__init__(parameters=None, return_annotation=<class 'IPython.utils.signatures._empty'>, __validate_parameters__=True)¶ Constructs Signature from the given list of Parameter objects and ‘return_annotation’. All arguments are optional.
-
bind(*args, **kwargs)¶ Get a
BoundArgumentsobject, that maps the passedargsandkwargsto the function’s signature. RaisesTypeErrorif the passed arguments can not be bound.
-
bind_partial(*args, **kwargs)¶ Get a
BoundArgumentsobject, that partially maps the passedargsandkwargsto the function’s signature. RaisesTypeErrorif the passed arguments can not be bound.
-
classmethod
from_function(func)¶ Constructs Signature for the given python function
-
replace(parameters=<class 'IPython.utils.signatures._void'>, return_annotation=<class 'IPython.utils.signatures._void'>)¶ Creates a customized copy of the Signature. Pass ‘parameters’ and/or ‘return_annotation’ arguments to override them in the new copy.
