From d39aed63a1f47a3c8b98ffe96339dfe45e70fad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A7=98=E7=9A=84man?= <2755488504@qq.com> Date: Sat, 31 Oct 2026 16:38:28 +0800 Subject: [PATCH] fix: Uncaught exception in get_normalizer_issues OSS-Contributor-Artifact: ef910267c6341da49dc992f9b0e1b23051f4cbcbacb023a41dd5cc1336d2ab98 --- parso/python/pep8.py | 2 +- tests/test_oss_regression_219.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/test_oss_regression_219.py 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