Skip to content

Commit eb7ddce

Browse files
made Keyword.__call__ only perform actual keyword func call if no switching errors happened before and fixed condition for context switching
--HG-- branch : draft
1 parent cb53ecf commit eb7ddce

1 file changed

Lines changed: 32 additions & 30 deletions

File tree

robottools/library/keywords/__init__.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __call__(self, *args, **kwargs):
158158
break
159159
# only perform explicit context switching
160160
# if explicit session switching didn't raise any error
161-
if error is not None:
161+
if error is None:
162162
current_contexts = {}
163163
for hcls in self.context_handlers:
164164
if not getattr(hcls, 'auto_explicit', False):
@@ -179,35 +179,37 @@ def __call__(self, *args, **kwargs):
179179
error = sys.exc_info()
180180
# don't switch any more contexts
181181
break
182-
# Look for arg type specs:
183-
if func.argtypes:
184-
casted = []
185-
for arg, argtype in zip(args, func.argtypes):
186-
if not isinstance(arg, argtype):
187-
arg = argtype(arg)
188-
casted.append(arg)
189-
args = tuple(casted) + args[len(func.argtypes):]
190-
# Look for context specific implementation of the Keyword function:
191-
for context, context_func in dictitems(func.contexts):
192-
if context in self.libinstance.contexts:
193-
func = context_func
194-
# Does the keyword support **kwargs?
195-
if self.func.argspec.keywords or not kwargs:
196-
result = func(self.libinstance, *args, **kwargs)
197-
else:
198-
# resolve **kwargs to positional args...
199-
posargs = []
200-
# (argspec.args start index includes self)
201-
for name in self.func.argspec.args[1 + len(args):]:
202-
if name in kwargs:
203-
posargs.append(kwargs.pop(name))
204-
# and turn the rest into *varargs in 'key=value' style
205-
varargs = ['%s=%s' % (key, kwargs.pop(key))
206-
for key in list(kwargs)
207-
if key not in self.func.argspec.args]
208-
result = func(self.libinstance, *chain(args, posargs, varargs),
209-
# if **kwargs left ==> TypeError from Python
210-
**kwargs)
182+
if error is None:
183+
# Look for arg type specs:
184+
if func.argtypes:
185+
casted = []
186+
for arg, argtype in zip(args, func.argtypes):
187+
if not isinstance(arg, argtype):
188+
arg = argtype(arg)
189+
casted.append(arg)
190+
args = tuple(casted) + args[len(func.argtypes):]
191+
# Look for context specific implementation of the Keyword function
192+
for context, context_func in dictitems(func.contexts):
193+
if context in self.libinstance.contexts:
194+
func = context_func
195+
# Does the keyword support **kwargs?
196+
if self.func.argspec.keywords or not kwargs:
197+
result = func(self.libinstance, *args, **kwargs)
198+
else:
199+
# resolve **kwargs to positional args...
200+
posargs = []
201+
# (argspec.args start index includes self)
202+
for name in self.func.argspec.args[1 + len(args):]:
203+
if name in kwargs:
204+
posargs.append(kwargs.pop(name))
205+
# and turn the rest into *varargs in 'key=value' style
206+
varargs = ['%s=%s' % (key, kwargs.pop(key))
207+
for key in list(kwargs)
208+
if key not in self.func.argspec.args]
209+
result = func(self.libinstance,
210+
*chain(args, posargs, varargs),
211+
# if **kwargs left ==> TypeError from Python
212+
**kwargs)
211213
# Switch back contexts and sessions (reverse order):
212214
for identifier, ctxname in dictitems(current_contexts):
213215
getattr(self.libinstance, 'switch_' + identifier)(ctxname)

0 commit comments

Comments
 (0)