mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-25 08:21:05 -06:00
Fixed bug in DefaultFrom where impleied keys were using entire func_code.co_varnames instead of an approprate slice
This commit is contained in:
parent
d615e4dafb
commit
bb978e591b
@ -121,7 +121,8 @@ class DefaultFrom(plugable.ReadOnly):
|
||||
raise TypeError('callback must be callable; got %r' % callback)
|
||||
self.callback = callback
|
||||
if len(keys) == 0:
|
||||
self.keys = callback.func_code.co_varnames
|
||||
fc = callback.func_code
|
||||
self.keys = fc.co_varnames[:fc.co_argcount]
|
||||
else:
|
||||
self.keys = keys
|
||||
for key in self.keys:
|
||||
|
@ -115,11 +115,21 @@ class test_DefaultFrom(ClassChecker):
|
||||
kw_copy = dict(kw)
|
||||
del kw_copy[key]
|
||||
assert o(**kw_copy) is None
|
||||
|
||||
# Test using implied keys:
|
||||
o = self.cls(lambda first, last: first[0] + last)
|
||||
assert o(first='john', last='doe') == 'jdoe'
|
||||
assert o(first='', last='doe') is None
|
||||
assert o(one='john', two='doe') is None
|
||||
|
||||
# Test that co_varnames slice is used:
|
||||
def callback2(first, last):
|
||||
letter = first[0]
|
||||
return letter + last
|
||||
o = self.cls(callback2)
|
||||
assert o.keys == ('first', 'last')
|
||||
assert o(first='john', last='doe') == 'jdoe'
|
||||
|
||||
|
||||
def test_parse_param_spec():
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user