(original) (raw)

changeset: 81831:49fd1c8aeca5 branch: 3.3 parent: 81829:678320c7f63d user: Antoine Pitrou solipsis@pitrou.net date: Tue Jan 29 21:20:57 2013 +0100 files: Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS description: Issue #17071: Signature.bind() now works when one of the keyword arguments is named ``self``. diff -r 678320c7f63d -r 49fd1c8aeca5 Lib/inspect.py --- a/Lib/inspect.py Tue Jan 29 20:14:08 2013 +0200 +++ b/Lib/inspect.py Tue Jan 29 21:20:57 2013 +0100 @@ -2028,19 +2028,19 @@ return self._bound_arguments_cls(self, arguments) - def bind(self, *args, **kwargs): + def bind(__bind_self, *args, **kwargs): '''Get a BoundArguments object, that maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. ''' - return self._bind(args, kwargs) + return __bind_self._bind(args, kwargs) - def bind_partial(self, *args, **kwargs): + def bind_partial(__bind_self, *args, **kwargs): '''Get a BoundArguments object, that partially maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. ''' - return self._bind(args, kwargs, partial=True) + return __bind_self._bind(args, kwargs, partial=True) def __str__(self): result = [] diff -r 678320c7f63d -r 49fd1c8aeca5 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Tue Jan 29 20:14:08 2013 +0200 +++ b/Lib/test/test_inspect.py Tue Jan 29 21:20:57 2013 +0100 @@ -2241,6 +2241,16 @@ with self.assertRaisesRegex(TypeError, "parameter is positional only"): self.call(test, a_po=1, b_po=2) + def test_signature_bind_with_self_arg(self): + # Issue #17071: one of the parameters is named "self + def test(a, self, b): + pass + sig = inspect.signature(test) + ba = sig.bind(1, 2, 3) + self.assertEqual(ba.args, (1, 2, 3)) + ba = sig.bind(1, self=2, b=3) + self.assertEqual(ba.args, (1, 2, 3)) + class TestBoundArguments(unittest.TestCase): def test_signature_bound_arguments_unhashable(self): diff -r 678320c7f63d -r 49fd1c8aeca5 Misc/NEWS --- a/Misc/NEWS Tue Jan 29 20:14:08 2013 +0200 +++ b/Misc/NEWS Tue Jan 29 21:20:57 2013 +0100 @@ -164,6 +164,9 @@ Library ------- +- Issue #17071: Signature.bind() now works when one of the keyword arguments + is named ``self``. + - Issue #12004: Fix an internal error in PyZipFile when writing an invalid Python file. Patch by Ben Morgan. /solipsis@pitrou.net