diff --git a/parso/python/pep8.py b/parso/python/pep8.py index 47db445..43cc9c0 100644 --- a/parso/python/pep8.py +++ b/parso/python/pep8.py @@ -444,7 +444,7 @@ def _visit_part(self, part, spacing, leaf): should_be_indentation = n.indentation self._last_indentation_tos = n - if n == node: + if n == node or n.parent is None: break n = n.parent diff --git a/tests/test_oss_regression_219.py b/tests/test_oss_regression_219.py new file mode 100644 index 0000000..698e787 --- /dev/null +++ b/tests/test_oss_regression_219.py @@ -0,0 +1,21 @@ +import parso +import pytest + + +@pytest.mark.parametrize('newline', ['\n', '\r\n', '\r']) +def test_comment_after_line_continuation(newline): + code = '\\' + newline + '#' + grammar = parso.load_grammar() + module = grammar.parse(code) + + try: + issues = grammar._get_normalizer_issues(module) + except AttributeError as error: + raise AssertionError( + 'A comment after a line continuation must not crash normalization' + ) from error + + assert [(issue.code, issue.start_pos) for issue in issues] == [ + (292, (2, 1)) + ] + assert module.get_code() == code