[Python-Dev] Rough idea for adding introspection information for builtins

Serhiy Storchaka storchaka at gmail.com
Tue Mar 19 08:37:35 CET 2013


On 19.03.13 06:45, Larry Hastings wrote:
> 4. Store a string that looks like the Python declaration of the
> signature, and parse it (Nick's suggestion).  For foo above, this would
> be "(arg,b=3,*,kwonly='a')".  Length: 23 bytes.

Strip parenthesis and it will be only 21 bytes long.

> We'd want one more mild hack: the DSL will support positional
> parameters, and inspect.Signature supports positional parameters, so
> it'd be nice to render that information.  But we can't represent that in
> Python syntax (or at least not yet!), so we can't let ast.parse see it.
> My suggestion: run it through ast.parse, and if it throws a SyntaxError
> see if the problem was a slash.  If it was, remove the slash, reprocess
> through ast.parse, and remember that all parameters are positional-only
> (and barf if there are kwonly, args, or kwargs).

It will be simpler to use some one-character separator which shouldn't 
be used unquoted in the signature. I.e. LF.



More information about the Python-Dev mailing list