Closed
Conversation
Signed-off-by: mshafer-NI <23644905+mshafer-NI@users.noreply.github.com>
…a name Signed-off-by: mshafer-NI <23644905+mshafer-NI@users.noreply.github.com>
Signed-off-by: mshafer-NI <23644905+mshafer-NI@users.noreply.github.com>
asottile
reviewed
May 23, 2025
| 700 statements | ||
| 900 syntax error | ||
| """ | ||
| import ast |
Member
There was a problem hiding this comment.
unfortunately one of the design principles of pycodestyle is that it does not use the ast to do its linting (this allows it to be ~somewhat cross-version compatible via the tokenizer)
so while this would work -- it can't be merged :(
Author
There was a problem hiding this comment.
May I suggest documenting that in CONTRIBUTING.rst?
Author
There was a problem hiding this comment.
Would you consider a PR that attempts ast and if there's any issue, falls back to the current method?
Member
There was a problem hiding this comment.
no I would not, that's why I closed this
Member
There was a problem hiding this comment.
and it's already in the docs:
Using the ast module defeats that purpose
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.
The current string based search for E731 (assignment of lambda to variable) relies on a text search. This breaks down if the lambda has a comment stored on it forcing a multi-line assignment in the form of:
However, existing tests indicate that
Should be considered acceptable, so merely stripping off paranthesis before evaluating would not work.
Implementation
By loading the "line" (in this example,
logical_linecomes in asf = (lambda x: 731 * x)) using the AST parser, we are able to check if there is an assignment of a Lambda to a Name.This allows all existing tests to pass while also resolving the new tests for E731.
Fixes #868