From 93f14157a62cb5207edc93b77396c1f1b58efe7c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 15 Mar 2017 18:41:58 +0100 Subject: [PATCH] Cleanup the ParseError stuff. --- jedi/evaluate/pep0484.py | 4 ++-- jedi/parser/__init__.py | 3 ++- jedi/parser/parser.py | 11 +++++------ jedi/parser/python/__init__.py | 2 +- test/test_parser/test_pgen2.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index ca2a52c8..5f543c9a 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -22,7 +22,7 @@ x support for type hint comments for functions, `# type: (int, str) -> int`. import itertools import os -from jedi.parser import ParseError, tree +from jedi.parser import ParserSyntaxError, tree from jedi.parser.python import parse from jedi.common import unite from jedi.evaluate.cache import memoize_default @@ -67,7 +67,7 @@ def _fix_forward_reference(context, node): start_symbol='eval_input', error_recovery=False ) - except ParseError: + except ParserSyntaxError: debug.warning('Annotation not parsed: %s' % evaled_node.obj) return node else: diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index da183116..f34b53fa 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -1,5 +1,6 @@ -from jedi.parser.parser import Parser, ParserWithRecovery, ParseError +from jedi.parser.parser import Parser, ParserWithRecovery, ParserSyntaxError from jedi.parser.pgen2.pgen import generate_grammar +from jedi.parser import python def parse(grammar, code): diff --git a/jedi/parser/parser.py b/jedi/parser/parser.py index 3cbc6982..aa086bee 100644 --- a/jedi/parser/parser.py +++ b/jedi/parser/parser.py @@ -24,13 +24,12 @@ from jedi.parser.token import (DEDENT, INDENT, ENDMARKER, NEWLINE, NUMBER, from jedi.parser.pgen2.parse import PgenParser -class ParseError(Exception): +class ParserSyntaxError(Exception): """ - Signals you that the code you fed the Parser was not correct Python code. + Contains error information about the parser tree. + + May be raised as an exception. """ - - -class ParserSyntaxError(object): def __init__(self, message, position): self.message = message self.position = position @@ -124,7 +123,7 @@ class Parser(object): def error_recovery(self, grammar, stack, arcs, typ, value, start_pos, prefix, add_token_callback): - raise ParseError + raise ParserSyntaxError('SyntaxError: invalid syntax', start_pos) def convert_node(self, grammar, type, children): """ diff --git a/jedi/parser/python/__init__.py b/jedi/parser/python/__init__.py index e2b327d1..ba03293f 100644 --- a/jedi/parser/python/__init__.py +++ b/jedi/parser/python/__init__.py @@ -5,7 +5,7 @@ import os from jedi._compatibility import FileNotFoundError from jedi.parser.pgen2.pgen import generate_grammar -from jedi.parser.parser import Parser, ParserWithRecovery, ParseError +from jedi.parser.parser import Parser, ParserWithRecovery from jedi.parser.tokenize import source_tokens diff --git a/test/test_parser/test_pgen2.py b/test/test_parser/test_pgen2.py index d03db9a4..a203a395 100644 --- a/test/test_parser/test_pgen2.py +++ b/test/test_parser/test_pgen2.py @@ -10,7 +10,7 @@ from textwrap import dedent from jedi._compatibility import is_py3 from jedi.parser.python import parse as _parse, load_grammar -from jedi.parser import ParseError +from jedi.parser import ParserSyntaxError import pytest from test.helpers import TestCase @@ -37,7 +37,7 @@ class GrammarTest(TestCase): def invalid_syntax(self, code, **kwargs): try: parse(code, **kwargs) - except ParseError: + except ParserSyntaxError: pass else: raise AssertionError("Syntax shouldn't have been valid")