cpython: 49fd1c8aeca5 (original) (raw)
Mercurial > cpython
changeset 81831:49fd1c8aeca5 3.3
Issue #17071: Signature.bind() now works when one of the keyword arguments is named ``self``. [#17071]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Tue, 29 Jan 2013 21:20:57 +0100 |
parents | 678320c7f63d |
children | 4ff1dc8c0a3c f39b69494393 |
files | Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS |
diffstat | 3 files changed, 17 insertions(+), 4 deletions(-)[+] [-] Lib/inspect.py 8 Lib/test/test_inspect.py 10 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2028,19 +2028,19 @@ class Signature: return self._bound_arguments_cls(self, arguments)
- def bind(__bind_self, *args, **kwargs):
'''Get a BoundArguments object, that maps the passed
args
andkwargs
to the function's signature. RaisesTypeError
if the passed arguments can not be bound. '''
return self._bind(args, kwargs)[](#l1.13)
return __bind_self._bind(args, kwargs)[](#l1.14)
- def bind_partial(__bind_self, *args, **kwargs):
'''Get a BoundArguments object, that partially maps the
passed
args
andkwargs
to the function's signature. RaisesTypeError
if the passed arguments can not be bound. '''
return self._bind(args, kwargs, partial=True)[](#l1.22)
return __bind_self._bind(args, kwargs, partial=True)[](#l1.23)
--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -2241,6 +2241,16 @@ class TestSignatureBind(unittest.TestCas 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[](#l2.8)
def test(a, self, b):[](#l2.9)
pass[](#l2.10)
sig = inspect.signature(test)[](#l2.11)
ba = sig.bind(1, 2, 3)[](#l2.12)
self.assertEqual(ba.args, (1, 2, 3))[](#l2.13)
ba = sig.bind(1, self=2, b=3)[](#l2.14)
self.assertEqual(ba.args, (1, 2, 3))[](#l2.15)
+ class TestBoundArguments(unittest.TestCase): def test_signature_bound_arguments_unhashable(self):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -164,6 +164,9 @@ Core and Builtins Library ------- +- Issue #17071: Signature.bind() now works when one of the keyword arguments