Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "raise … from …" #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rplugin/python3/semshi/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ def __init__(self, name, lineno, col, env, target=None, hl_group=None):
else:
try:
self.symbol = self.env[-1].lookup(self.symname)
except KeyError:
except KeyError as exc:
# Set dummy hl group, so all fields in __repr__ are defined.
self.hl_group = '?'
raise Exception('%s can\'t lookup "%s"' % (self, self.symname))
raise Exception(
'%s can\'t lookup "%s"' % (self, self.symname)
) from exc
if hl_group is not None:
self.hl_group = hl_group
else:
Expand Down
8 changes: 4 additions & 4 deletions rplugin/python3/semshi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def parse(self, *args, **kwargs):
return self._parse(*args, **kwargs)
except (SyntaxError, RecursionError) as e:
logger.debug('parsing error: %s', e)
raise UnparsableError(e)
raise UnparsableError(e) from e
finally:
self.tick += 1

Expand Down Expand Up @@ -135,22 +135,22 @@ def _fix_syntax_and_make_ast(self, code, lines, change_lineno):
new_code = lines_to_code(new_lines)
try:
ast_root = self._make_ast(new_code)
except SyntaxError:
except SyntaxError as exc:
# Restore original line
new_lines[error_idx] = orig_line
# Fixing the line of the syntax error failed, so try again with the
# line of last change.
if change_lineno is None or change_lineno == error_idx:
# Don't try to fix the changed line if it's unknown or the same
# as the one we tried to fix before.
raise orig_error
raise orig_error from exc
new_lines[change_lineno] = self._fix_line(new_lines[change_lineno])
new_code = lines_to_code(new_lines)
try:
ast_root = self._make_ast(new_code)
except SyntaxError:
# All fixing attempts failed, so raise original syntax error.
raise orig_error
raise orig_error from exc
return ast_root, new_code, new_lines, orig_error

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion rplugin/python3/semshi/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,6 @@ def _convert_excluded_hl_groups(items):
return [hl_groups[g] for g in items]
except KeyError as e:
# TODO Use err_write instead?
raise Exception('"%s" is an unknown highlight group.' % e.args[0])
raise Exception(
'"%s" is an unknown highlight group.' % e.args[0]
) from e