-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation for fluent interface check #287
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sbrugman ! Everything looks good for the most part, just a few changes and this should be good to merge.
Thanks for the review, will incorporate the changes |
feea90e
to
bb8e5f8
Compare
Finally got around to continuing on this PR. Updated the code to the next one available (184) Handling returns could reuse logic from the assignment case, so I expanded the functionality to handle certain return statements. Also excluded multiple references to the assigned variable in the call expression itself, e.g. def _(x):
y = x.m()
return y.operation(*[v for v in y]) |
9c02deb
to
6090977
Compare
6090977
to
77b6806
Compare
Thank you for the new updates! Things look good for the most part, though this is causing one of the FURB177 test to fail: import pathlib
from pathlib import Path
# these should match
_ = Path().resolve()
_ = Path("").resolve() # noqa: FURB153
_ = Path(".").resolve() # noqa: FURB153
_ = pathlib.Path().resolve()
... FURB184 is being emitted on line 8:
Though the error seems to go away if you use |
Thanks, I'll have a look |
Fixed. (The name argument was not correctly passed down in the recursion) The example also made me think that we should exclude |
f87f9f3
to
af33006
Compare
Sorry for the late response, the holidays have been pretty chaotic this year! The tests are passing now, but I found another false-positive: def f(x):
if x:
name = "alice"
stripped = name.strip()
else:
name = "bob"
print(name) Because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment.
Also I just approved CI workflows for this PR, so CI is failing because of linter errors. I ran your changes locally, and the tests are passing.
Thanks! I've updated the implementation to restrict it to top-level definitions, and fixed linting & typing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me!
Also, the was_referenced
property isn't being used anymore, so I'll remove that real quick and then merge this!
Implementation for #286
Basic code for what the implementation for the rule proposed could look like.
By design it only considers the simplest case for now: a sequential assignment to the same variable with method chaining.
I left the error code open (999). For the test cases I "mocked" the APIs, this works fine but could be cleaner.
Awaiting the discussion on the issues page, I have not extensively checked this implementation in the wild.
The rule could be extended:
assign
)flake8-return
R504)