From f9e1f2bda930054eed3115e19e9f3f7bfc83c1b6 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Wed, 2 Mar 2016 11:07:47 -0500 Subject: inspect: Fix BoundArguments.apply_defaults to handle empty arguments Patch by Frederick Wagner (issue #26347) --- Lib/inspect.py | 2 -- Lib/test/test_inspect.py | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index b65bec7..e830eb6 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 69ddb51..671e05a 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): -- cgit v0.12