[Python-checkins] cpython (3.5): inspect: Fix BoundArguments.apply_defaults to handle empty arguments

yury.selivanov python-checkins at python.org
Wed Mar 2 11:09:46 EST 2016


https://hg.python.org/cpython/rev/94879997ea5f
changeset:   100396:94879997ea5f
branch:      3.5
parent:      100394:ef5265bc07bb
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Wed Mar 02 11:07:47 2016 -0500
summary:
  inspect: Fix BoundArguments.apply_defaults to handle empty arguments

Patch by Frederick Wagner (issue #26347)

files:
  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
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2591,8 +2591,6 @@
         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
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -3324,6 +3324,13 @@
         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):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list