Refactor a bit for Python 2.

This commit is contained in:
Dave Halter
2017-07-31 10:27:57 +02:00
parent 84ed1af1e4
commit 5fbbb225dd
6 changed files with 48 additions and 41 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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))