cpython: 4ff1dc8c0a3c (original) (raw)
Mercurial > cpython
changeset 81832:4ff1dc8c0a3c
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:21:56 +0100 |
parents | e24fd2c35d27(current diff)49fd1c8aeca5(diff) |
children | 0880e0f859e0 |
files | Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS |
diffstat | 3 files changed, 18 insertions(+), 5 deletions(-)[+] [-] Lib/inspect.py 8 Lib/test/test_inspect.py 10 Misc/NEWS 5 |
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 @@ -236,10 +236,13 @@ Core and Builtins Library ------- +- Issue #17071: Signature.bind() now works when one of the keyword arguments
- Issue #12004: Fix an internal error in PyZipFile when writing an invalid Python file. Patch by Ben Morgan. -Have py_compile use importlib as much as possible to avoid code duplication. +- Have py_compile use importlib as much as possible to avoid code duplication.
- Issue #180022: Have site.addpackage() consider already known paths even when none are explicitly passed in. Bug report and fix by Kirill.