Skip to content

Commit 3483a9b

Browse files
additional **kwargs handling fix in Keyword.__call__
1 parent 6e8fb1c commit 3483a9b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

robottools/library/keywords/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,20 @@ def __call__(self, *args, **kwargs):
166166
# Does the keyword support **kwargs?
167167
if self.func.argspec.keywords or not kwargs:
168168
result = func(self.libinstance, *args, **kwargs)
169-
else: # Pass them as *varargs in 'key=value' style to the Keyword:
169+
else:
170+
# resolve **kwargs to positional args...
171+
posargs = []
172+
# (argspec.args start index includes self)
173+
for name in self.func.argspec.args[1 + len(args):]:
174+
if name in kwargs:
175+
posargs.append(kwargs.pop(name))
176+
# and turn the rest into *varargs in 'key=value' style
170177
varargs = ['%s=%s' % (key, kwargs.pop(key))
171178
for key in list(kwargs)
172179
if key not in self.func.argspec.args]
173-
result = func(self.libinstance, *chain(args, varargs))
180+
result = func(self.libinstance, *chain(args, posargs, varargs),
181+
# if **kwargs left ==> TypeError from Python
182+
**kwargs)
174183
# Switch back contexts and sessions (reverse order):
175184
for identifier, ctxname in dictitems(current_contexts):
176185
getattr(self.libinstance, 'switch_' + identifier)(ctxname)

0 commit comments

Comments
 (0)