single |
.. funcsigs documentation master file, created by
sphinx-quickstart on Fri Apr 20 20:27:52 2012.
You can adapt this file completely to your liking, but it should at
least
contain the root `toctree` directive.
Introducing funcsigs
====================
The Funcsigs Package
--------------------
``funcsigs`` is a backport of the `PEP 362`_ function signature features
from
Python 3.3's `inspect`_ module. The backport is compatible with Python
2.6, 2.7
as well as 3.3 and up. 3.2 was supported by version 0.4, but with
setuptools and
pip no longer supporting 3.2, we cannot make any statement about 3.2
compatibility.
Compatibility
`````````````
The ``funcsigs`` backport has been tested against:
* CPython 2.6
* CPython 2.7
* CPython 3.3
* CPython 3.4
* CPython 3.5
* CPython nightlies
* PyPy and PyPy3(currently failing CI)
Continuous integration testing is provided by `Travis CI`_.
Under Python 2.x there is a compatibility issue when a function is
assigned to
the ``__wrapped__`` property of a class after it has been constructed.
Similiarily there under PyPy directly passing the ``__call__`` method of a
builtin is also a compatibility issues. Otherwise the functionality is
believed to be uniform between both Python2 and Python3.
Issues
``````
Source code for ``funcsigs`` is hosted on `GitHub`_. Any bug reports or
feature
requests can be made using GitHub's `issues system`_. |build_status|
|coverage|
Example
-------
To obtain a `Signature` object, pass the target function to the
``funcsigs.signature`` function.
.. code-block:: python
>>> from funcsigs import signature
>>> def foo(a, b=None, *args, **kwargs):
... pass
...
>>> sig = signature(foo)
>>> sig
>>> sig.parameters
OrderedDict([('a', ), ('b', ), ('args', ), ('kwargs', )])
>>> sig.return_annotation
Introspecting callables with the Signature object
-------------------------------------------------
.. note::
This section of documentation is a direct reproduction of the Python
standard library documentation for the inspect module.
The Signature object represents the call signature of a callable object
and its
return annotation. To retrieve a Signature object, use the
:func:`signature`
function.
.. function:: signature(callable)
Return a :class:`Signature` object for the given ``callable``::
>>> from funcsigs import signature
>>> def foo(a, *, b:int, **kwargs):
... pass
>>> sig = signature(foo)
>>> str(sig)
'(a, *, b:int, **kwargs)'
>>> str(sig.parameters['b'])
'b:int'
>>> sig.parameters['b'].annotation
Accepts a wide range of python callables, from plain functions and
classes to
:func:`functools.partial` objects.
.. note::
|