Message215317
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. |
|
Date |
User |
Action |
Args |
2014-04-01 13:59:25 | r.david.murray | set | recipients:
+ r.david.murray, brett.cannon, ncoghlan, larry, yselivanov |
2014-04-01 13:59:25 | r.david.murray | set | messageid: <1396360765.29.0.731173040518.issue21117@psf.upfronthosting.co.za> |
2014-04-01 13:59:25 | r.david.murray | link | issue21117 messages |
2014-04-01 13:59:24 | r.david.murray | create | |
|