Skip to content
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

Feature Request: No Useless List Unpack-Repack #534

Closed
Skylion007 opened this issue Sep 30, 2023 · 2 comments
Closed

Feature Request: No Useless List Unpack-Repack #534

Skylion007 opened this issue Sep 30, 2023 · 2 comments

Comments

@Skylion007
Copy link
Contributor

Description

Saw this is in a discussion on RUFF: astral-sh/ruff#7618

Thread just mentions this construct[*x] as opposed to just calling list(x). Not only is the later more readable, I would assume it's more efficient because lack of arg unpack (we should benchmark it though)? You may want to add a rule to flag this weird construct.

@adamchainz
Copy link
Owner

Sounds sensible but let’s not assume and do a benchmark first. dicts can also be constructed via unpack so the rule could cover both.

@adamchainz
Copy link
Owner

Unpacking is faster, presumably because it doesn't need to look up the name list. So, let's leave this.

In [1]: items = list(range(10))

In [2]: %timeit list(items)
52.1 ns ± 0.144 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In [3]: %timeit [*items]
34.5 ns ± 0.173 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

@adamchainz adamchainz closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2024
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

No branches or pull requests

2 participants