Conversation
commented_out_code_line_numbers tests each comment line on its own and the test ends in compile(), so a call that was wrapped when it was commented out is never recognised: 'foo(a,' is not a statement by itself. The module already has a mechanism for continuation lines, but it only covers an assignment, not a call. Consecutive comment lines are now grouped into bracket-balanced fragments and compiled as a whole. A group is only formed when a line is left unfinished by its brackets, so ordinary prose, which is balanced line by line, is untouched. The whitelist that protects 'noqa' and 'TODO' comments moved into a shared helper; it used to sit inside the single-line branch only, which would have let a protected comment be swallowed as part of a group. Fixes PyCQA#36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #36.
commented_out_code_line_numberstests each comment line on its own, and the test ends incompile(). A call that was wrapped when it was commented out never compiles line by line —foo(a,is not a statement — so nothing is reported:The module already handles continuation lines, but that path only covers an assignment, not a call.
Consecutive comment lines are now grouped into bracket-balanced fragments and compiled as a whole. A group is only formed when a line is left unfinished by its brackets, so ordinary prose — balanced line by line — never forms one.
Measured
python -m unittest test_eradicate: 30 passed before and after.# foo(a,/# b)# run(timeout=5,/# retries=3)# xs = [1,/# 2]# Hello/# World# We do this (see/# the docs)# Note that x (the/# counter) is reset# As shown in (Smith/# 2019), this works# noqa: E501 (/# continued# TODO: foo(/# bar)Two phrases do change:
# Hello (world/# and more)and# items (a, b,/# c, d)become reported. Both compile as calls, and the current release already reports them when the same phrase is written on one line —# items (a, b, c, d)is reported today. So this makes the wrapped and unwrapped spellings agree rather than adding a new class of match.The whitelist protecting
noqaandTODOcomments moved into a shared helper. It used to sit inside the single-line branch only, so without the move a protected comment could have been swallowed as part of a group.AI-assisted (LLM used for drafting); the runs above are mine.