Kaydet (Commit) f9e1f2bd authored tarafından Yury Selivanov's avatar Yury Selivanov

inspect: Fix BoundArguments.apply_defaults to handle empty arguments

Patch by Frederick Wagner (issue #26347)
üst 1bd03078
......@@ -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:
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment