[Python-Dev] The docstring hack for signature information has to go

Larry Hastings larry at hastings.org
Thu Feb 6 04:19:29 CET 2014


On 02/05/2014 05:52 AM, "Martin v. Löwis" wrote:
> D: Add a new type slot for method signatures. This would be a
> tp_signature field, along with a new slot id Py_tp_signature. The
> signature field itself could be
>
> struct PyMethodSignature {
>     char *method_name;
>     char *method_signature;
> };

That should work too, though we'd also have to add a md_signature field 
to module objects.

It would probably be best to merge the signature into the callable 
object anyway.  Otherwise we'd have to go look up the signature using 
__name__ and __self__ / __objclass__ on demand.  Maybe that isn't such a 
big deal, but it gets a little worse: as far as I can tell, there's no 
attribute on a type object one can use to find the module it lives in.  
So in this situation:

     >>> import _pickle
     >>> import inspect
     >>> inspect.signature(_pickle.Pickler)

How could inspect.signature figure out that the "Pickler" type object 
lives in the "_pickle" module?  My best guess: parsing the __qualname__, 
which is pretty ugly.

Also, keeping the signature as a reasonably-human-readable preface to 
the docstring means that, if we supported this for third-party modules, 
they could be binary ABI compatible with 3.3 and still have something 
approximating the hand-written signature at the top of their docstring.

Cheers,


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140205/098bbf33/attachment.html>


More information about the Python-Dev mailing list