Point to prototype implementation. Also clarify 'name' attribute on Signature

is not fully qualified.
This commit is contained in:
Brett Cannon 2006-08-22 22:03:11 +00:00
parent 2b89abe649
commit 1f41623653
1 changed files with 22 additions and 12 deletions

View File

@ -15,12 +15,13 @@ Abstract
========
Python has always supported powerful introspection capabilities,
including that for functions. Taking a function object, you can fully
reconstruct the function signature using ``func_defaults``,
``func_code.co_argcount``, ``func_code.co_flags``, and
``func_code.co_varnames``. Unfortunately this is a little unruly
having to look at four different attributes to pull together complete
information for a function's signature.
including that for functions and methods (for the rest of this PEP the
word "function" refers to both functions and methods). Taking a
function object, you can fully reconstruct the function signature
using ``func_defaults``, ``func_code.co_argcount``,
``func_code.co_flags``, and ``func_code.co_varnames``. Unfortunately
this is a little unruly having to look at four different attributes
to pull together complete information for a function's signature.
This PEP proposes an object representation for function signatures.
This should help facilitate introspection on functions. It also helps
@ -40,7 +41,12 @@ parameters that are highly unique (.e.g, ``*args``).
A Signature object has the following structure attributes:
* name:str
Name of the function.
Name of the function. This is not fully qualified because
function objects for methods do not know the class they are
contained within. This makes functions and methods
indistinguishable from one another when passed to decorators,
prevventing proper creation of a fully qualified name.
indistinguishable from
* var_args:str
Name of the ``*args`` parameter, if present, else the empty
string.
@ -94,11 +100,12 @@ The structure of the Parameter object is:
Implementation
==============
An implementation is forthcoming for experimentation purposes based on
the 'inspect' module [#inspect-module]_. The classes will be exposed
in the 'inspect' module as well. This PEP has been posted without
implementation so as to not be a hinderance to another PEP that is
under development by another author.
An implementation can be found in patch #1544909 [#impl]_. It
modifies the 'inspect' module [#inspect-module]_to include the
implementation. There is a function named ``getsignature()`` which
returns the value stored on the ``__signature__`` attribute (for
methods this is stored directly on the im_func function object since
that is what decorators will work with).
Relation With Other PEPs
@ -144,6 +151,9 @@ References
.. [#pep-3102] Keyword-Only Arguments
(http://www.python.org/dev/peps/pep-3102/)
.. [#impl] Implementation of PEP 362
(http://www.python.org/sf/1544909)
Copyright
=========