[Python-Dev] PEP 362 Third Revision

Victor Stinner victor.stinner at gmail.com
Thu Jun 14 14:06:09 CEST 2012


Sorry if I'm asking dummy questions, I didn't follow the discussion.

> * 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.

Hum, what are these "custom render functions"? Can you give an example?

> * is_keyword_only : bool
>    True if the parameter is keyword-only, else False.
> * is_args : bool
>    True if the parameter accepts variable number of arguments
>    (``*args``-like), else False.
> * is_kwargs : bool
>    True if the parameter accepts variable number of keyword
>    arguments (``**kwargs``-like), else False.

Hum, why not using a attribute with a string value instead of 3
attribute? For example:
 * argtype: "index", "varargs", "keyword" or "keyword_only"

It would avoid a possible inconsitency (ex: is_args=True and
is_kwargs=True). And it would help to implement something like a C
switch/case using a dict: argtype => function for functions using
signatures.

> * is_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 ``is_implemented`` may be False be
>    thoroughly documented.

I suppose that the value depends on the running platform? (For
example, you may get a different value on Linux and Windows.)

> Implementation
> ==============
>
>    - If the object has a ``__signature__`` attribute and if it
>      is not ``None`` - return a deepcopy of it

Oh, why copying the object? It may impact performances. If fhe caller
knows that it will modify the signature, it can deepcopy the
signature.

>        - If it is ``None`` and the object is an instance of
>          ``BuiltinFunction``, raise a ``ValueError``

What about builtin functions (ex: len)? Do you plan to add a
__signature__ attribute? If yes, something created on demand or
created at startup?

It would be nice to have a C API to create Signature objects, maybe
from the same format string than PyArg_Parse*() functions. But it can
be implemented later.

Is it possible to build a Signature object from a string describing
the prototype (ex: "def f(x, y): pass")? (I mean: do you plan to add
such function?)

--

Except of these remarks, I like this PEP :-)

Victor


More information about the Python-Dev mailing list