Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9e1f2b

Browse files
committed
inspect: Fix BoundArguments.apply_defaults to handle empty arguments
Patch by Frederick Wagner (issue #26347)
1 parent 1bd0307 commit f9e1f2b

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/inspect.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,8 +2591,6 @@ def apply_defaults(self):
25912591
empty dict.
25922592
"""
25932593
arguments = self.arguments
2594-
if not arguments:
2595-
return
25962594
new_arguments = []
25972595
for name, param in self._signature.parameters.items():
25982596
try:

Lib/test/test_inspect.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,6 +3324,13 @@ def foo(): pass
33243324
ba.apply_defaults()
33253325
self.assertEqual(list(ba.arguments.items()), [])
33263326

3327+
# Make sure a no-args binding still acquires proper defaults.
3328+
def foo(a='spam'): pass
3329+
sig = inspect.signature(foo)
3330+
ba = sig.bind()
3331+
ba.apply_defaults()
3332+
self.assertEqual(list(ba.arguments.items()), [('a', 'spam')])
3333+
33273334

33283335
class TestSignaturePrivateHelpers(unittest.TestCase):
33293336
def test_signature_get_bound_param(self):

0 commit comments

Comments
 (0)