From 5f52099ff8351871eb1fbc2717035946f92bbf0d Mon Sep 17 00:00:00 2001 From: doctaphred Date: Thu, 11 Feb 2016 22:12:52 -0500 Subject: [PATCH] Make apply_defaults work for empty arguments Previously, BoundArguments.apply_defaults would return immediately when its arguments were empty, rather than filling in missing values from self._signature.parameters. --- 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 74f3b3c..582bb0e 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2571,8 +2571,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 98d596e..76cebcc 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -3325,6 +3325,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): -- 2.5.1