-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
style: Fixes unnecessary-collection-call (C408) for empty collections #3945
Merged
echoix
merged 3 commits into
OSGeo:main
from
echoix:fix-empty-unnecessary-collection-call
Jul 1, 2024
Merged
style: Fixes unnecessary-collection-call (C408) for empty collections #3945
echoix
merged 3 commits into
OSGeo:main
from
echoix:fix-empty-unnecessary-collection-call
Jul 1, 2024
Conversation
This file contains 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
Only applies fixes to empty collections by `ruff check --select "C408" --unsafe-fixes --fix --config "lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments = true"` in order to limit the review scope.
github-actions
bot
added
GUI
wxGUI related
raster
Related to raster data processing
Python
Related code is in Python
libraries
module
general
tests
Related to Test Suite
labels
Jun 30, 2024
ninsbl
previously approved these changes
Jul 1, 2024
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.
Please see my one comment...
Co-authored-by: Stefan Blumentrath <stefan.blumentrath@gmx.de>
ninsbl
approved these changes
Jul 1, 2024
cyliang368
pushed a commit
to cyliang368/grass
that referenced
this pull request
Jul 1, 2024
…OSGeo#3945) * style: Fixes unnecessary-collection-call (C408) for empty collections Only applies fixes to empty collections by `ruff check --select "C408" --unsafe-fixes --fix --config "lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments = true"` in order to limit the review scope. * style: apply black * Apply suggestions from code review --------- Co-authored-by: Stefan Blumentrath <stefan.blumentrath@gmx.de>
Merged
a0x8o
pushed a commit
to a0x8o/grass
that referenced
this pull request
Jul 2, 2024
…OSGeo#3945) * style: Fixes unnecessary-collection-call (C408) for empty collections Only applies fixes to empty collections by `ruff check --select "C408" --unsafe-fixes --fix --config "lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments = true"` in order to limit the review scope. * style: apply black * Apply suggestions from code review --------- Co-authored-by: Stefan Blumentrath <stefan.blumentrath@gmx.de>
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.
Only applies fixes to empty collections by
ruff check --select "C408" --unsafe-fixes --fix --config "lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments = true"
in order to limit the review scope.Part of preparing the repo for Pylint 3.x for #3921
Uses the fixes provided for ruff rule unnecessary-collection-call (C408) to fix part of Pylint's use-dict-literal / R1735 rule. I say "Part of", as for this PR I limited it to only the empty initializers.
Using literals instead of function calls is faster, as it doesn't require to load from global scope (to make sure "list" or "dict" wasn't changed to something else). Also, for the same reason it is better to import the functions to put them in scope (from xyz import thatfunc") instead of just using "import xyz" and then calling "xyz.thatfunc()" (it is slower to go fetch in xyz in global scope and then fetching thatfunc in that scope than importing it once, especially in loops).
Here, it says 3x faster (using
[]
instead oflist()
saves 1 opcode, and the[]
avoids theLOAD_NAME
opcode. https://ealexbarros.medium.com/why-is-faster-than-list-in-python-5bef48b530fcHere, where it is analyzed for Python 3.12 in 2024, it goes in the same direction https://madebyme.today/blog/python-dict-vs-curly-brackets/, plus explains that
{}
uses a pre-allocated dict and adds the values if needed.