Skip to content

Commit 3582a5b

Browse files
simplified some try except logic in Keyword.__call__
--HG-- branch : dev
1 parent e998d9e commit 3582a5b

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

robottools/library/keywords/__init__.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,17 @@ def __call__(self, *args, **kwargs):
147147
try:
148148
sname = kwargs.pop(identifier)
149149
except KeyError:
150-
pass
151-
else:
152-
previous = getattr(self.libinstance, identifier)
153-
switch = getattr(self.libinstance, 'switch_' + identifier)
154-
try:
155-
switch(sname)
156-
except hcls.SessionError:
157-
error = sys.exc_info()
158-
# don't switch any more sessions
159-
break
160-
# store previous session for switching back later
161-
current_sessions[identifier, plural_identifier] = previous
150+
continue
151+
previous = getattr(self.libinstance, identifier)
152+
switch = getattr(self.libinstance, 'switch_' + identifier)
153+
try:
154+
switch(sname)
155+
except hcls.SessionError:
156+
error = sys.exc_info()
157+
# don't switch any more sessions
158+
break
159+
# store previous session for switching back later
160+
current_sessions[identifier, plural_identifier] = previous
162161
# only perform explicit context switching
163162
# if explicit session switching didn't raise any error
164163
current_contexts = {}
@@ -170,19 +169,17 @@ def __call__(self, *args, **kwargs):
170169
try:
171170
ctxname = kwargs.pop(identifier)
172171
except KeyError:
173-
pass
174-
else:
175-
previous = getattr(self.libinstance, identifier)
176-
switch = getattr(self.libinstance,
177-
'switch_' + identifier)
178-
try:
179-
switch(ctxname)
180-
except hcls.ContextError:
181-
error = sys.exc_info()
182-
# don't switch any more contexts
183-
break
184-
# store previous context for switching back later
185-
current_contexts[identifier] = previous
172+
continue
173+
previous = getattr(self.libinstance, identifier)
174+
switch = getattr(self.libinstance, 'switch_' + identifier)
175+
try:
176+
switch(ctxname)
177+
except hcls.ContextError:
178+
error = sys.exc_info()
179+
# don't switch any more contexts
180+
break
181+
# store previous context for switching back later
182+
current_contexts[identifier] = previous
186183
# only call the acutal keyword func
187184
# if explicit session and context switching didn't raise any error
188185
if error is None:

0 commit comments

Comments
 (0)