Skip to content

Fix normalizer crash on comments after line continuations - #247

Closed
salapenar-max wants to merge 1 commit into
davidhalter:masterfrom
salapenar-max:fix/comment-after-line-continuation
Closed

salapenar-max wants to merge 1 commit into
davidhalter:masterfrom
salapenar-max:fix/comment-after-line-continuation

Conversation

@salapenar-max

Copy link
Copy Markdown

A comment after an explicit line continuation, such as "\\\n#", crashes the PEP8 normalizer with AttributeError: 'NoneType' object has no attribute 'indentation'. This still reproduces on current master.

The backslash introduces an indentation node while processing the same leaf prefix, so the previous indentation stack does not necessarily contain the current node. Stop the comment-indentation search at the root as well as at the current node, instead of walking into None.

Add 12 regression cases covering LF, CRLF, and CR line endings, one or two line continuations, and empty or nonempty comments. They assert that the normalizer reports the expected missing-newline diagnostic and its position.

Fixes #219.

Validation on Linux/Python 3.13.12:

  • Reproduced the original crash before the fix; the initial six line-ending/continuation regressions also failed with that exception.
  • python -m pytest -q: 2,000 passed, including the 12 final regression cases.
  • Repository-pinned Flake8 5.0.4 passes for both changed Python files.
  • git diff --check passes.

AI disclosure: OpenAI Codex investigated the report, authored the patch and regression tests, and ran the checks on behalf of the submitting account owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught exception in get_normalizer_issues

3 participants