From: Yury Selivanov Date: Wed, 2 Mar 2016 16:07:47 +0000 (-0500) Subject: inspect: Fix BoundArguments.apply_defaults to handle empty arguments X-Git-Tag: v3.6.0a1~538^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9e1f2bda930054eed3115e19e9f3f7bfc83c1b6;p=python inspect: Fix BoundArguments.apply_defaults to handle empty arguments Patch by Frederick Wagner (issue #26347) --- diff --git a/Lib/inspect.py b/Lib/inspect.py index b65bec7adf..e830eb64ca 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2591,8 +2591,6 @@ class BoundArguments: empty dict. """ arguments = self.arguments - if not arguments: - return new_arguments = [] for name, param in self._signature.parameters.items(): try: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 69ddb514d6..671e05a7b5 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -3324,6 +3324,13 @@ class TestBoundArguments(unittest.TestCase): ba.apply_defaults() self.assertEqual(list(ba.arguments.items()), []) + # Make sure a no-args binding still acquires proper defaults. + def foo(a='spam'): pass + sig = inspect.signature(foo) + ba = sig.bind() + ba.apply_defaults() + self.assertEqual(list(ba.arguments.items()), [('a', 'spam')]) + class TestSignaturePrivateHelpers(unittest.TestCase): def test_signature_get_bound_param(self):