Skip to content

Enforce ruff rules using pre-commit#484

Open
DimitriPapadopoulos wants to merge 8 commits intoen-wl:v2from
DimitriPapadopoulos:ruff
Open

Enforce ruff rules using pre-commit#484
DimitriPapadopoulos wants to merge 8 commits intoen-wl:v2from
DimitriPapadopoulos:ruff

Conversation

@DimitriPapadopoulos
Copy link
Copy Markdown
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Feb 18, 2026

Use the pre-commit GitHub Action although:

this action is in maintenance-only mode and will not be accepting new features.

The alternative would be to give pre-commit.ci access to the repository.

Requires enabling GitHub Actions for this repository.

@DimitriPapadopoulos DimitriPapadopoulos changed the title Enforce ruff rules Enforce ruff rules using pre-commit Feb 18, 2026
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the ruff branch 3 times, most recently from 2ff848a to 3b46531 Compare February 18, 2026 13:06
(sg.id, group_id))

if li.action == 'remove' or li.action == 'transfer':
if li.action in {'remove', 'transfer'}:
Copy link
Copy Markdown
Member

@kevina kevina Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set has a fixed overhead, for a small number of elements a tuple would be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
$ 

Copy link
Copy Markdown
Member

@kevina kevina Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You tested with a list, not a tuple. In any case I still prefer using a tuple in these cases. Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
$ 

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the ruff branch 2 times, most recently from add1480 to a7bd8e5 Compare February 22, 2026 09:51
@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review February 22, 2026 09:52
@DimitriPapadopoulos
Copy link
Copy Markdown
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants