diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 993848f..c32bb97 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -430,7 +430,7 @@ class ErrorFinder(Normalizer): self._add_syntax_error(message % p.name.value, p.name) param_names.add(p.name.value) - if p.default is None: + if p.default is None and not p.star_count: if default_only: # def f(x=3, y): pass message = "non-default argument follows default argument" @@ -510,6 +510,9 @@ class ErrorFinder(Normalizer): yield + if node.type == 'suite': + self._indentation_count -= 1 + def visit_leaf(self, leaf): if leaf.type == 'error_leaf': if leaf.original_type in ('indent', 'error_dedent'): @@ -597,7 +600,7 @@ class ErrorFinder(Normalizer): elif leaf.value == 'break': in_loop = False for block in self._context.blocks: - if block.type == 'for_stmt': + if block.type in ('for_stmt', 'while_stmt'): in_loop = True if not in_loop: self._add_syntax_error("'break' outside loop", leaf) diff --git a/test/test_file_python_errors.py b/test/test_file_python_errors.py new file mode 100644 index 0000000..6c733a2 --- /dev/null +++ b/test/test_file_python_errors.py @@ -0,0 +1,23 @@ +import os + +import parso + + +def get_python_files(path): + for dir_path, dir_names, file_names in os.walk(path): + for file_name in file_names: + if file_name.endswith('.py'): + yield os.path.join(dir_path, file_name) + + +def test_parso_files(each_version): + """ + There are obviously no syntax erros in the Python code of parso. However + parso should output the same for all versions. + """ + grammar = parso.load_grammar(version=each_version) + path = os.path.dirname(os.path.dirname(__file__)) + '/parso' + for file in get_python_files(path): + tree = grammar.parse(path=file) + errors = list(tree._iter_errors(grammar)) + assert not errors