diff --git a/rplugin/python3/semshi/node.py b/rplugin/python3/semshi/node.py index b006a5a..2c81a9c 100644 --- a/rplugin/python3/semshi/node.py +++ b/rplugin/python3/semshi/node.py @@ -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: diff --git a/rplugin/python3/semshi/parser.py b/rplugin/python3/semshi/parser.py index cded728..d708835 100644 --- a/rplugin/python3/semshi/parser.py +++ b/rplugin/python3/semshi/parser.py @@ -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 @@ -135,7 +135,7 @@ 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 @@ -143,14 +143,14 @@ def _fix_syntax_and_make_ast(self, code, lines, change_lineno): 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 diff --git a/rplugin/python3/semshi/plugin.py b/rplugin/python3/semshi/plugin.py index 534a2e0..ad55d3b 100644 --- a/rplugin/python3/semshi/plugin.py +++ b/rplugin/python3/semshi/plugin.py @@ -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