Module: utils.signatures — IPython 2.3.1 documentation

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »

# 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: `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.

  `__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: `object`

  Result of `Signature.bind()` call. Holds the mapping of arguments to the function’s parameters.

  Has the following public attributes:

  arguments : `collections.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.
  `__init__`(signature, arguments)

class `IPython.utils.signatures.` `Signature`(parameters=None, return_annotation=<class 'IPython.utils.signatures._empty'>, __validate_parameters__=True)

  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:

  parameters : `collections.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
    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.
  `__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 `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)

    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)

    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.

## 2 Functions

`IPython.utils.signatures.` `formatannotation`(annotation, base_module=None)

`IPython.utils.signatures.` `signature`(obj)

  Get a signature object for the passed callable.

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »