◐ Shell
clean mode source ↗

Message 215317 - Python tracker

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.