-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement perflint
#4789
Comments
Also rules from https://github.com/tonybaloney/anti-patterns |
If that's a separate plugin it's best to make a different issue for that. As for perflint, I will wait until the first PR is merged before looking at further rules. |
Rules checklist: EDIT: Added to Issue body |
@qdegraaf I can pick up some of these - are there any that you're particularly interested in? Don't want to overstep |
Thanks @qdegraaf - I went ahead and added that to the issue body :) |
Awesome! I've got an almost complete PERF101. Otherwise haven't picked up anything yet. I'll open a draft PR for PERF101 and otherwise take your pick! Feel free to ping me on the Discord if you want to collaborate or check availability. |
I can grab PERF203 and PERF301 to start. |
I'll start looking at 401 and 402 EDIT: Picked up 403 in a separate PR as well. I can leave the 2X and 3X to you if you like @evanrittenhouse |
## Summary Adds PERF101 which checks for unnecessary casts to `list` in for loops. NOTE: Is not fully equal to its upstream implementation as this implementation does not flag based on type annotations (i.e.): ```python def foo(x: List[str]): for y in list(x): ... ``` With the current set-up it's quite hard to get the annotation from a function arg from its binding. Problem is best considered broader than this implementation. ## Test Plan Added fixture. ## Issue links Refers: #4789 --------- Co-authored-by: Charlie Marsh <[email protected]>
@qdegraaf You can grab 3X as well! I'll do 2X, if that works for you? |
Rules from perflint are derived from tonybaloney/anti-patterns. So these 2 rules (join with generator and regex with IGNORECASE) should be part of perflint or RUF rules? |
@charliermarsh what's the protocol for this. I think it makes functional sense to add it to
Cool, works for me! If I get round to them at some point in the near future I'll make sure to announce it here. Feel free to change your mind in the meantime if you find time before me. |
## Summary Implements PERF203 from #4789, which throws if a `try/except` block is inside of a loop. Not sure if we want to extend the diagnostic to the `except` as well, but I thought that that may get a little messy. We may also want to just throw on the word `try` - open to suggestions though. ## Test Plan `cargo test`
## Summary Adds `PERF401` and `PERF402` mirroring `W8401` and `W8402` from https://github.com/tonybaloney/perflint Implementation is not super smart but should be at parity with upstream implementation judging by: https://github.com/tonybaloney/perflint/blob/c07391c17671c3c9d5a7fd69120d1f570e268d58/perflint/comprehension_checker.py#L42-L73 It essentially checks: - If the body of a for-loop is just one statement - If that statement is an `if` and the if-statement contains a call to `append()` we flag `PERF401` and suggest a list comprehension - If that statement is a plain call to `append()` or `insert()` we flag `PERF402` and suggest `list()` or `list.copy()` I've set the violation to only flag the first append call in a long `if-else` statement for `PERF401`. Happy to change this to some other location or make it multiple violations if that makes more sense. ## Test Plan Fixtures were added with the relevant scenarios for both rules ## Issue Links Refers: #4789
PERF203 should only trigger when there’s no loop flow control ( for repo in ['R-patched', 'cran', 'bioc']:
try:
pkg_cache = self._fetch_cache(repo, pkg)
break
except HTTPError:
pass
else:
return None |
https://github.com/tonybaloney/perflint - Python Linter for performance anti patterns.
The text was updated successfully, but these errors were encountered: