mirror of
https://github.com/python/cpython.git
synced 2025-09-05 00:11:10 +00:00
inspect: Fix BoundArguments.apply_defaults to handle empty arguments
Patch by Frederick Wagner (issue #26347)
This commit is contained in:
parent
1bd030788d
commit
f9e1f2bda9
2 changed files with 7 additions and 2 deletions
|
@ -2591,8 +2591,6 @@ class BoundArguments:
|
||||||
empty dict.
|
empty dict.
|
||||||
"""
|
"""
|
||||||
arguments = self.arguments
|
arguments = self.arguments
|
||||||
if not arguments:
|
|
||||||
return
|
|
||||||
new_arguments = []
|
new_arguments = []
|
||||||
for name, param in self._signature.parameters.items():
|
for name, param in self._signature.parameters.items():
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -3324,6 +3324,13 @@ class TestBoundArguments(unittest.TestCase):
|
||||||
ba.apply_defaults()
|
ba.apply_defaults()
|
||||||
self.assertEqual(list(ba.arguments.items()), [])
|
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):
|
class TestSignaturePrivateHelpers(unittest.TestCase):
|
||||||
def test_signature_get_bound_param(self):
|
def test_signature_get_bound_param(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue