Author Jelle Zijlstra
Recipients Jelle Zijlstra, nedbat
Date 2016-06-02.18:43:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464893012.2.0.283607184635.issue19611@psf.upfronthosting.co.za>
In-reply-to
Content
This doesn't work in Python 3.6 (current dev version) either. Using Ned's example, I get (snipping some of the ipython stack trace):

/home/jelle/cpython-dev/cpython/Lib/inspect.py in __init__(self, name, kind, default, annotation)
   2399         if not name.isidentifier():
-> 2400             raise ValueError('{!r} is not a valid parameter name'.format(name))
   2401 

ValueError: '.0' is not a valid parameter name

print(inspect.Signature.from_callable(setcomp_func).bind(iter(range(5))))
fails with the same error.

However, both work if I take out the isidentifier check.

In Python 2.7, the bug is actually in inspect.getargs:

In [7]: inspect.getargs(setcomp_func.func_code)
Out[7]: Arguments(args=[['z']], varargs=None, keywords=None)

which assumes that any ".0" argument is a tuple.


I'm not sure the bug in 2.7 is worth fixing, since it will require fragile bytecode manipulation to distinguish tuple arguments from set comprehensions, and you can get to this case only by manually creating function objects. 

I think the Python 3 level bug is worth fixing though, since it's an easy fix (just make the .isidentifier call accept names of the form .0). I'm attaching a patch against master with tests. I have signed the contributor agreement.
History
Date User Action Args
2016-06-02 18:43:32Jelle Zijlstrasetrecipients: + Jelle Zijlstra, nedbat
2016-06-02 18:43:32Jelle Zijlstrasetmessageid: <1464893012.2.0.283607184635.issue19611@psf.upfronthosting.co.za>
2016-06-02 18:43:32Jelle Zijlstralinkissue19611 messages
2016-06-02 18:43:32Jelle Zijlstracreate