Skip to content

Commit

Permalink
[py]: use native mapping .get(...) in error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
symonk committed Jul 14, 2022
1 parent 21c693d commit 545355d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions py/selenium/webdriver/remote/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ def check_response(self, response: Dict[str, Any]) -> None:
stacktrace = []
try:
for frame in st_value:
line = self._value_or_default(frame, 'lineNumber', '')
file = self._value_or_default(frame, 'fileName', '<anonymous>')
line = frame.get("lineNumber", "")
file = frame.get("fileName", "<anonymous>")
if line:
file = f"{file}:{line}"
meth = self._value_or_default(frame, 'methodName', '<anonymous>')
meth = frame.get('methodName', '<anonymous>')
if 'className' in frame:
meth = "{}.{}".format(frame['className'], meth)
msg = " at %s (%s)"
Expand All @@ -245,6 +245,3 @@ def check_response(self, response: Dict[str, Any]) -> None:
alert_text = value['alert'].get('text')
raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
raise exception_class(message, screen, stacktrace)

def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT:
return obj[key] if key in obj else default

0 comments on commit 545355d

Please sign in to comment.