diff --git a/conftest.py b/conftest.py index bf66a26..55c8a38 100644 --- a/conftest.py +++ b/conftest.py @@ -111,6 +111,7 @@ class Checker(): def __init__(self, version, is_passing): self.version = version self._is_passing = is_passing + self.grammar = parso.load_grammar(version=self.version) def parse(self, code): if self._is_passing: @@ -125,7 +126,7 @@ class Checker(): print(module.children) def get_error(self, code): - errors = list(parso.parse(code, version=self.version)._iter_errors()) + errors = list(self.grammar.parse(code)._iter_errors(self.grammar)) assert bool(errors) != self._is_passing if errors: return errors[0] @@ -138,7 +139,7 @@ class Checker(): def assert_no_error_in_passing(self, code): if self._is_passing: - assert not list(parso.parse(code, version=self.version)._iter_errors()) + assert not list(self.grammar.parse(code)._iter_errors(self.grammar)) @pytest.fixture diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 60715a6..3694b63 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from contextlib import contextmanager from parso.normalizer import Normalizer, NormalizerConfig, Issue @@ -656,3 +657,6 @@ class ErrorFinder(Normalizer): class ErrorFinderConfig(NormalizerConfig): normalizer_class = ErrorFinder + + def __init__(self, grammar): + self.grammar = grammar diff --git a/parso/python/tree.py b/parso/python/tree.py index d199be7..4540385 100644 --- a/parso/python/tree.py +++ b/parso/python/tree.py @@ -99,8 +99,8 @@ class PythonMixin(object): return result return None - def _iter_errors(self): - config = normalizer.ErrorFinderConfig() + def _iter_errors(self, grammar): + config = normalizer.ErrorFinderConfig(grammar) return self._get_normalizer_issues(config) diff --git a/test/normalizer_issue_files/allowed_syntax.py b/test/normalizer_issue_files/allowed_syntax.py index 14681e5..2a7346e 100644 --- a/test/normalizer_issue_files/allowed_syntax.py +++ b/test/normalizer_issue_files/allowed_syntax.py @@ -39,38 +39,3 @@ except: pass except ZeroDivisionError: pass - - -def c(): - a = 3 - - def d(): - class X(): - nonlocal a - - -def x(): - a = 3 - - def y(): - nonlocal a - - -def x(): - def y(): - nonlocal a - - a = 3 - - -def x(): - a = 3 - - def y(): - class z(): - nonlocal a - - -a = *args, *args -error[(*args, *args)] = 3 -*args, *args diff --git a/test/normalizer_issue_files/allowed_syntax_python3.6.py b/test/normalizer_issue_files/allowed_syntax_python3.6.py index a21a608..1bbe071 100644 --- a/test/normalizer_issue_files/allowed_syntax_python3.6.py +++ b/test/normalizer_issue_files/allowed_syntax_python3.6.py @@ -8,3 +8,38 @@ foo[3]: int def glob(): global x y: foo = x + + +def c(): + a = 3 + + def d(): + class X(): + nonlocal a + + +def x(): + a = 3 + + def y(): + nonlocal a + + +def x(): + def y(): + nonlocal a + + a = 3 + + +def x(): + a = 3 + + def y(): + class z(): + nonlocal a + + +a = *args, *args +error[(*args, *args)] = 3 +*args, *args diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 440dcc7..923d2dd 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ Testing if parso finds syntax errors and indentation errors. """ @@ -218,8 +219,9 @@ if sys.version_info >= (3, 4): def _get_error_list(code, version=None): - tree = parso.parse(code, version=version) - config = ErrorFinderConfig() + grammar = parso.load_grammar(version=version) + tree = grammar.parse(code) + config = ErrorFinderConfig(grammar=grammar) return list(tree._get_normalizer_issues(config))