]> granicus.if.org Git - python/commitdiff
Issue #17071: Signature.bind() now works when one of the keyword arguments is named...
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 29 Jan 2013 20:20:57 +0000 (21:20 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 29 Jan 2013 20:20:57 +0000 (21:20 +0100)
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS

index 88f0ee2fc111c7a1b02f80a38a49f99f93e67015..7a7bb91b1be84c5594278934c714370ee91a6a9c 100644 (file)
@@ -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 = []
index 80db03bf0004e4337456ebf2c8e184d8649e983c..6e3f04e68a0d37a019e9a2768fdb0472d69d4887 100644 (file)
@@ -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):
index ce8c088fa6c894c63d964b804fac4351bac2ed29..66bdb03a2ca04ea2e94df195fc9d0ec230a87443 100644 (file)
--- 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
+  is named ``self``.
+
 - Issue #12004: Fix an internal error in PyZipFile when writing an invalid
   Python file.  Patch by Ben Morgan.