classification
Title: Signature.bind() fails with a keyword argument named "self"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, haypo, larry, pitrou, python-dev, yselivanov
Priority: normal Keywords: patch

Created on 2013-01-29 13:10 by pitrou, last changed 2013-01-29 21:40 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
sig_bind_self.patch pitrou, 2013-01-29 18:43 review
Messages (8)
msg180906 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-01-29 13:10
>>> def f(a, self): pass
... 
>>> sig = inspect.signature(f)
>>> sig.bind(1, 2)
<inspect.BoundArguments object at 0x7f607ead1e28>
>>> sig.bind(a=1, self=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bind() got multiple values for argument 'self'
msg180909 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2013-01-29 15:08
I'll take a look later today.
msg180926 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-01-29 18:43
Here is a patch.
msg180937 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2013-01-29 19:28
Thanks Antoine, the patch looks good to me.

The only thing I would have done differently myself is to name "self" as "__bind_self__" (with two underscores at the end).

Could you please apply the patch?
msg180943 - (view) Author: Roundup Robot (python-dev) Date: 2013-01-29 20:24
New changeset 49fd1c8aeca5 by Antoine Pitrou in branch '3.3':
Issue #17071: Signature.bind() now works when one of the keyword arguments is named ``self``.
http://hg.python.org/cpython/rev/49fd1c8aeca5

New changeset 4ff1dc8c0a3c by Antoine Pitrou in branch 'default':
Issue #17071: Signature.bind() now works when one of the keyword arguments is named self.
http://hg.python.org/cpython/rev/4ff1dc8c0a3c
msg180944 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-01-29 20:26
Committed to 3.3 and default!
msg180951 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-01-29 21:38
self doesn't need to have a name, you can use:

def bind(*args, **kw):
  self = args[0]
  args = args[1:]

To accept any name ;-)
msg180952 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-01-29 21:40
Indeed, there were several solutions to this.
History
Date User Action Args
2013-01-29 21:40:36pitrousetmessages: + msg180952
2013-01-29 21:38:38hayposetnosy: + haypo
messages: + msg180951
2013-01-29 20:26:09pitrousetstatus: open -> closed
resolution: fixed
messages: + msg180944

stage: resolved
2013-01-29 20:24:54python-devsetnosy: + python-dev
messages: + msg180943
2013-01-29 19:28:36yselivanovsetmessages: + msg180937
2013-01-29 18:43:55pitrousetfiles: + sig_bind_self.patch
keywords: + patch
messages: + msg180926
2013-01-29 15:08:38yselivanovsetmessages: + msg180909
2013-01-29 13:11:04hayposetnosy: + brett.cannon
2013-01-29 13:10:35pitroulinkissue17015 dependencies
2013-01-29 13:10:10pitroucreate