This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author larry
Recipients brett.cannon, georg.brandl, gvanrossum, larry
Date 2013-11-20.23:52:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1384991546.24.0.134873558554.issue19674@psf.upfronthosting.co.za>
In-reply-to
Content
Let's see if we can get introspection information for builtins using the Clinic for 3.4.

Georg suggested part of the approach while we were hanging out in Tokyo.  I'd considered it previously before but dispensed with the idea because it seemed too loopy.  Actually it seems to work great.  

The approach:

* Clinic generates an extra first line for the docstring, that looks like "def (...)\n".  (Note: no function name!)

* The PyCFunctionObject __doc__ getter detects this line and skips it if present.

* Add a new getter to PyCFunctionObject, which I've called "__textsig__", that returns this first line if present in the docstring.  (It skips the "def " at the front, and clips it at the newline.)

* inspect now notices if it's passed in a PyCFunctionObject.  If it gets one, it checks to see if it has a valid __textsig__.  If it does, it parses it (using ast.parse) and produces a valid signature.

Advantages of this approach:
* It was easy to do and took very few lines of code.

* For signatures that are impossible to convert to Clinic, we can
  write the metadata by hand.

Disadvantages of this approach:
* Uh, nothing, really!

The next step is probably to convert pydoc to use inspect.signature instead of the manky old methods it currently uses.  After that, clean up the patch, and add a unit test or two.

What do you think?
History
Date User Action Args
2013-11-20 23:52:27larrysetrecipients: + larry, gvanrossum, brett.cannon, georg.brandl
2013-11-20 23:52:26larrysetmessageid: <1384991546.24.0.134873558554.issue19674@psf.upfronthosting.co.za>
2013-11-20 23:52:26larrylinkissue19674 messages
2013-11-20 23:52:26larrycreate