forked from VimPlug/jedi
Cleanup the ParseError stuff.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user