Remove a useless pass separated from the next statement - #363
Open
Eljees wants to merge 1 commit into
Open
Conversation
useless_pass_line_numbers recognises a leading pass only when the next real token sits on the row immediately after it. A blank line or a comment shifts that row, so the pass is never marked and survives. The pending pass is now carried across non-ATOM tokens and resolved on the first ATOM token, with the pending state cleared on any ATOM rather than only a matching one: otherwise an atom at the same indentation in a later, unrelated block would be taken for the continuation of this one. Fixes PyCQA#65
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 #65.
useless_pass_line_numbersrecognises a leadingpassonly when the next real token sits on the row immediately after it:A blank line or a comment shifts that row, so the
passis never marked and survives:The pending
passis now carried across non-ATOM tokens (NL,COMMENT,INDENT,DEDENT) and resolved on the first ATOM token. The pending state is cleared on any ATOM rather than only a matching one — otherwise an atom at the same indentation in a later, unrelated block would be taken for the continuation of this one.Measured
python -m pytest(excludingtest_fuzz.py, which needs a corpus): 174 passed before and after.pass, blank line, statementpass, comment, statementpassimmediately before a statementpassas the only statement in a functionThe comment case is what shows this is line arithmetic rather than anything specific to blank lines.
Two things worth saying plainly:
passwas is not removed. autoflake doesn't manage blank lines and this change doesn't start; the issue text reads as if it should, so I'd rather name the difference than let it be discovered in review.[2, 2]); it now yields it once. Nothing visible changes, since the numbers feed a membership test.This touches
useless_pass_line_numbersonly. #349 rewritesfilter_useless_passfurther down the same file; the hunks don't meet.AI-assisted (LLM used for drafting); the runs above are mine.