[issue21117] inspect.signature: inaccuracies for partial functions

R. David Murray report at bugs.python.org
Tue Apr 1 15:59:25 CEST 2014


R. David Murray added the comment:

OK, I didn't even realize that was possible with partial.  Now I understand Yuri's original point.  His example is wrong:

>>> def foo(a, b):
...    print(a, b)
>>> x2 = partial(foo, 'x')
>>> str(inspect.signature(x2))
'(b)'

This is the correct example:

>>> x = partial(foo, a='x')
>>> x('b')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for argument 'a'

The current signature for this is the one Yuri gave:

>>> str(inspect.signature(x))
"(a='x', b)"

Which is about as close as one can come to the rather non-intuitve (non-pythonic?) behavior that partial has here.  Perhaps this a bug in partial?  If so it is unfortunately one with ugly backward compatibility implications.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21117>
_______________________________________


More information about the Python-bugs-list mailing list