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

Larry Hastings larry at hastings.org
Tue Feb 4 11:18:08 CET 2014



On 02/03/2014 02:26 PM, Antoine Pitrou wrote:
> How do you create an array that mixes PyMethodDefs and PyMethodDefExs
> together?

You're right, you wouldn't be able to.  For my PyMethodDefEx proposal, 
the entire array would have to be one way or the other.


> It sounds like METH_SIGNATURE is the wrong mechanism.
> Instead, you may want a tp_methods_ex as well as as a
> Py_TPFLAGS_HAVE_METHODS_EX.

You may well be right.  We'd already need a flag on the type object 
anyway, to indicate "tp_doc start with a signature".  So if we had such 
a flag, it could do double-duty to also indicate "tp_methods points to 
PyMethodDefEx structures".

My only concern here: __text_signature__ is supported on five internal 
objects: PyCFunctionObject, PyTypeObject, PyMethodDescr_Type, 
_PyMethodWrapper_Type, and PyWrapperDescr_Type. I'm not certain that all 
of those carry around their own pointer back to their original type object.

If you went off the "self" parameter, you wouldn't have one if you were 
an unbound method.  And you might get the wrong answer if the user bound 
you to a different class, or if you were accessed through a subclass.  
(I say "might" not to mean "it could happen sometimes", but rather "I 
don't know what the correct answer is".)


> Note that this constrains future growth to only add pointer fields,
> unless you also add a couple of long fields. But at least it sounds
> workable.

Ah, in the back of my mind I meant to say "add some unused union {void 
*p; long i;} fields".  Though in practice I don't think we support any 
platforms where sizeof(long) > sizeof(void *).


> Uh... If you write a "conversion function", you may as well make it so
> it converts the "sig=" line to a plain signature line in 3.3, which
> avoids the issue entirely.

Yeah, that's an improvement, though it makes the conversion function a 
lot more complicated, and presumably uses more memory.


> (and how would that conversion function be shipped to the user anyway?
> Python 3.3 and the stable ABI don't have it)

As a C function in a text file, that they'd have to copy into their 
program.  I know it's ugly.


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140204/79c79582/attachment.html>


More information about the Python-Dev mailing list