Enforce ruff rules using pre-commit#484
Open
DimitriPapadopoulos wants to merge 8 commits intoen-wl:v2from
Open
Enforce ruff rules using pre-commit#484DimitriPapadopoulos wants to merge 8 commits intoen-wl:v2from
DimitriPapadopoulos wants to merge 8 commits intoen-wl:v2from
Conversation
d9c3461 to
fd9051c
Compare
2ff848a to
3b46531
Compare
kevina
reviewed
Feb 19, 2026
libscowl/_adjust.py
Outdated
| (sg.id, group_id)) | ||
|
|
||
| if li.action == 'remove' or li.action == 'transfer': | ||
| if li.action in {'remove', 'transfer'}: |
Member
There was a problem hiding this comment.
Set has a fixed overhead, for a small number of elements a tuple would be better.
Contributor
Author
There was a problem hiding this comment.
I'm not sure that's true in practice:
$ python -m timeit -s 'l = ["remove", "transfer"]; "foo" in l'
50000000 loops, best of 5: 6.16 nsec per loop
$ python -m timeit -s 'l = ["remove", "transfer"]; "foo" in l'
50000000 loops, best of 5: 6.15 nsec per loop
$ python -m timeit -s 'l = ["remove", "transfer"]; "foo" in l'
50000000 loops, best of 5: 6.22 nsec per loop
$ python -m timeit -s 'l = ["remove", "transfer"]; "foo" in l'
50000000 loops, best of 5: 6.34 nsec per loop
$ python -m timeit -s 'l = ["remove", "transfer"]; "foo" in l'
50000000 loops, best of 5: 6.14 nsec per loop
$ python -m timeit -s 'l = ["remove", "transfer"]; "foo" in l'
50000000 loops, best of 5: 6.14 nsec per loop
$
$ python -m timeit -s 's = {"remove", "transfer"}; "foo" in s'
50000000 loops, best of 5: 6.16 nsec per loop
$ python -m timeit -s 's = {"remove", "transfer"}; "foo" in s'
50000000 loops, best of 5: 6.17 nsec per loop
$ python -m timeit -s 's = {"remove", "transfer"}; "foo" in s'
50000000 loops, best of 5: 6.19 nsec per loop
$ python -m timeit -s 's = {"remove", "transfer"}; "foo" in s'
50000000 loops, best of 5: 6.16 nsec per loop
$ python -m timeit -s 's = {"remove", "transfer"}; "foo" in s'
50000000 loops, best of 5: 6.15 nsec per loop
$
Member
There was a problem hiding this comment.
You tested with a list, not a tuple. In any case I still prefer using a tuple in these cases. Thank you.
Contributor
Author
There was a problem hiding this comment.
Same with a tuple:
$ python -m timeit -s 'l = ("remove", "transfer"); "foo" in l'
50000000 loops, best of 5: 6.37 nsec per loop
$ python -m timeit -s 'l = {"remove", "transfer"}; "foo" in l'
50000000 loops, best of 5: 6.03 nsec per loop
$
$ python -m timeit -s 'l = ("remove", "transfer"); "foo" in l'
50000000 loops, best of 5: 6 nsec per loop
$ python -m timeit -s 'l = {"remove", "transfer"}; "foo" in l'
50000000 loops, best of 5: 6.02 nsec per loop
$
$ python -m timeit -s 'l = ("remove", "transfer"); "foo" in l'
50000000 loops, best of 5: 6.02 nsec per loop
$ python -m timeit -s 'l = {"remove", "transfer"}; "foo" in l'
50000000 loops, best of 5: 6.01 nsec per loop
$ add1480 to
a7bd8e5
Compare
Contributor
Author
|
I would suggest using prek as a drop-in replacement for pre-commit. The associated j178/prek-action is fully maintained. |
Unnecessary generator (rewrite as a set comprehension)
Unnecessary `map()` usage (rewrite using a generator expression)
Use a dictionary comprehension instead of a for-loop
Consider merging multiple comparisons
Use `sys.exit()` instead of `exit`
Use `elif` instead of `else` then `if`, to reduce indentation
a7bd8e5 to
ba50717
Compare
f3a50ff to
ca99bb4
Compare
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.
Use the pre-commit GitHub Action although:
The alternative would be to give pre-commit.ci access to the repository.
Requires enabling GitHub Actions for this repository.