[Python-checkins] peps: Committing the latest changes to PEP 362 on behalf of Yury Selivanov.

larry.hastings python-checkins at python.org
Tue Jun 19 11:38:28 CEST 2012


http://hg.python.org/peps/rev/659639095ace
changeset:   4466:659639095ace
user:        Larry Hastings <larry at hastings.org>
date:        Tue Jun 19 02:38:15 2012 -0700
summary:
  Committing the latest changes to PEP 362 on behalf of Yury Selivanov.

files:
  pep-0362.txt |  66 ++++++++++++---------------------------
  1 files changed, 21 insertions(+), 45 deletions(-)


diff --git a/pep-0362.txt b/pep-0362.txt
--- a/pep-0362.txt
+++ b/pep-0362.txt
@@ -58,20 +58,19 @@
     of some required arguments (mimics ``functools.partial``
     behavior.)  Raises a ``TypeError`` if the passed arguments do
     not match the signature.
-* format(...) -> str
-    Formats the Signature object to a string.  Optional arguments allow
-    for custom render functions for parameter names,
-    annotations and default values, along with custom separators.
 
-Signature implements the ``__str__`` method, which fallbacks to the
-``Signature.format()`` call.
-
-It's possible to test Signatures for equality.  Two signatures
-are equal when they have equal parameters and return annotations.
+It's possible to test Signatures for equality.  Two signatures are
+equal when their parameters are equal, their positional and
+positional-only parameters appear in the same order, and they
+have equal return annotations.
 
 Changes to the Signature object, or to any of its data members,
 do not affect the function itself.
 
+Signature also implements ``__str__`` and ``__copy__`` methods.
+The latter creates a shallow copy of Signature, with all Parameter
+objects copied as well.
+
 
 Parameter Object
 ================
@@ -125,16 +124,8 @@
          that aren't bound to any other parameter. This corresponds
          to a "\*\*kwds" parameter in a Python function definition.
 
-* implemented : bool
-    True if the parameter is implemented for use.  Some platforms
-    implement functions but can't support specific parameters
-    (e.g. "mode" for ``os.mkdir``).  Passing in an unimplemented
-    parameter may result in the parameter being ignored,
-    or in NotImplementedError being raised.  It is intended that
-    all conditions where ``implemented`` may be False be
-    thoroughly documented.
-
-Two parameters are equal when all their attributes are equal.
+Two parameters are equal when they have equal names, kinds, defaults,
+and annotations.
 
 
 BoundArguments Object
@@ -181,10 +172,7 @@
     - If the object is not callable - raise a TypeError
 
     - If the object has a ``__signature__`` attribute and if it
-      is not ``None`` - return a deepcopy of it
-
-        - If it is ``None`` and the object is an instance of
-          ``BuiltinFunction``, raise a ``ValueError``
+      is not ``None`` - return a shallow copy of it
 
     - If it has a ``__wrapped__`` attribute, return
       ``signature(object.__wrapped__)``
@@ -218,7 +206,7 @@
 
 Note, that the ``Signature`` object is created in a lazy manner, and
 is not automatically cached.  If, however, the Signature object was
-explicitly cached by the user, ``signature()`` returns a new deepcopy
+explicitly cached by the user, ``signature()`` returns a new shallow copy
 of it on each invocation.
 
 An implementation for Python 3.3 can be found at [#impl]_.
@@ -244,6 +232,15 @@
     is different from the actual one
 
 
+Some functions may not be introspectable
+----------------------------------------
+
+Some functions may not be introspectable in certain implementations of
+Python.  For example, in CPython, builtin functions defined in C provide
+no metadata about their arguments.  Adding support for them is out of
+scope for this PEP.
+
+
 Examples
 ========
 
@@ -437,28 +434,6 @@
         return wrapper
 
 
-Render Function Signature to HTML
----------------------------------
-
-::
-
-    import inspect
-
-    def format_to_html(func):
-        sig = inspect.signature(func)
-
-        html = sig.format(token_params_separator='<span class="t-comma">,</span>',
-                          token_colon='<span class="t-colon">:</span>',
-                          token_eq='<span class="t-eq">=</span>',
-                          token_return_annotation='<span class="t-ra">-&gt;</span>',
-                          token_left_paren='<span class="t-lp">(</span>',
-                          token_right_paren='<span class="t-lp">)</span>',
-                          token_kwonly_separator='<span class="t-ast">*</span>',
-                          format_name=lambda name: '<span class="name">'+name+'</span>')
-
-        return '<span class="py-func">{}</span>'.format(html)
-
-
 References
 ==========
 

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list