summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-03-02 11:07:47 -0500
committerYury Selivanov <yselivanov@sprymix.com>2016-03-02 11:07:47 -0500
commitf9e1f2bda930054eed3115e19e9f3f7bfc83c1b6 (patch)
tree8b021183fe8aa457ab0c74d5d409525e4f8b543e
parent1bd030788d1092ba5d5d8b4e2fd75346ded69b3b (diff)
downloadcpython-git-f9e1f2bda930054eed3115e19e9f3f7bfc83c1b6.tar.gz
inspect: Fix BoundArguments.apply_defaults to handle empty arguments
Patch by Frederick Wagner (issue #26347)
-rw-r--r--Lib/inspect.py2
-rw-r--r--Lib/test/test_inspect.py7
2 files changed, 7 insertions, 2 deletions
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):