Skip to content

Prefer unpacking over concatenating (RUF005) #2230

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Mar 26, 2024

This also opens the door to using more tuples and generators in these places for further optimizations
Used Ruff to find these and prevent regressions

https://docs.astral.sh/ruff/rules/collection-literal-concatenation/

[...] collections can be concatenated more efficiently using the unpacking operator (e.g., [*x, *y] to concatenate x and y).
[...] The * operator can unpack any iterable, whereas + operates only on particular sequences which, in many cases, must be of the same type.

Closes #775

Copy link
Owner

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

I'm fairly ambivalent about this one - I think ever Python programmer understands list concatenation. What's the motivation here?

@Avasam Avasam changed the title Prefer unpacking over concatenating Prefer unpacking over concatenating (RUF005) Dec 11, 2024
This also opens the door to using more tuples and generators in these places for further optimizations
Used Ruff to prevent regressions
@Avasam Avasam force-pushed the unpacking-over-concatenating branch from 8f1f4ec to a64dc22 Compare December 31, 2024 02:23
@Avasam
Copy link
Collaborator Author

Avasam commented Dec 31, 2024

What's the motivation here?

The idea is to get more performant code, essentially "for free" (as in you don't have to think much about it, since it's autofixed).

This would be even better if astral-sh/ruff#10592 gets implemented. In the mean time I've fixed nested unpacking manually (searching for regex \*\(.*\*.+\) and for the string *tuple)

@Avasam Avasam force-pushed the unpacking-over-concatenating branch from 6e4f3bc to d5795b5 Compare December 31, 2024 03:32
@Avasam Avasam requested a review from mhammond April 8, 2025 01:25
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.

Minor Client Speedup
2 participants