- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
Ruff rules for comprehensions, performance, and simplicity #23040
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
Conversation
edff17e    to
    dd3c9bc      
    Compare
  
    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.
Most of these look great!
Thanks for working on this.
        
          
                tools/toolchain_profiler.py
              
                Outdated
          
        
      | @staticmethod | ||
| def escape_args(args): | ||
| return map(lambda arg: ToolchainProfiler.escape_string(arg), args) | ||
| return (ToolchainProfiler.escape_string(arg) for arg in args) | 
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.
Just return a list here maybe?  [ToolchainProfiler.escape_string(arg) for arg in args]
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.
map() returns an iterator in Python 3 so the linter's fix wants to return a generator expression.  Lists take more RAM than maps and generators.
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.
Sure, this is far from memory critical code though and I think the explicit list is more idiomatic (at least to my old fasioned eyes).
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.
I will change this but...
The Py 2 to 3 transition contained a few key transitions.
- bytes == strvs.- bytes != str
- https://docs.python.org/3/whatsnew/3.0.html#print-is-a-function (and related changes)
- https://docs.python.org/3/whatsnew/3.0.html#views-and-iterators-instead-of-lists
Lists were more idiomatic in legacy Python but the push towards iterators was quite deliberate.
| Can you include the command line you used to generate this PR (in the PR description). | 
cf2cfe9    to
    8c9e584      
    Compare
  
    bcef3ea    to
    b28ffa6      
    Compare
  
    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.
lgtm! Thanks for working on this.
…n-core#23040) Only in the `tools/` directory apply ruff rules for comprehensions, performance, and simplicity. * https://docs.astral.sh/ruff * https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 * https://docs.astral.sh/ruff/rules/#perflint-perf * https://docs.astral.sh/ruff/rules/#flake8-simplify-sim This pull request was roughly created via the command: `ruff --select=C4,PERF,Q,SIM --ignore=SIM108,SIM300 lint.flake8-quotes.inline-quotes=single --fix --unsafe-fixes`
Only in the
tools/directory apply ruff rules for comprehensions, performance, and simplicity.This pull request was roughly created via the command:
ruff --select=C4,PERF,Q,SIM --ignore=SIM108,SIM300 lint.flake8-quotes.inline-quotes=single --fix --unsafe-fixes