Jelle Zijlstra added the comment:
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.
----------
keywords: +patch
nosy: +Jelle Zijlstra
Added file: http://bugs.python.org/file43105/issue19611.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19611>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com