summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-01-29 20:20:57 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-01-29 20:20:57 (GMT)
commitbd41d1b14c03e76c6ebf396720eddba60f00c8dc (patch)
tree6c3861261529c87b46fad3f7406dc7f1a22f653b /Lib
parentc5b75db5def1890924d914bc36b54e6a120bf2d7 (diff)
downloadcpython-bd41d1b14c03e76c6ebf396720eddba60f00c8dc.zip
cpython-bd41d1b14c03e76c6ebf396720eddba60f00c8dc.tar.gz
cpython-bd41d1b14c03e76c6ebf396720eddba60f00c8dc.tar.bz2
Issue #17071: Signature.bind() now works when one of the keyword arguments is named ``self``.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/inspect.py8
-rw-r--r--Lib/test/test_inspect.py10
2 files changed, 14 insertions, 4 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 88f0ee2..7a7bb91 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2028,19 +2028,19 @@ class Signature:
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 --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 80db03b..6e3f04e 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -2241,6 +2241,16 @@ class TestSignatureBind(unittest.TestCase):
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):