Skip to content

[mypyc] Don't copy items twice in list(<generator expression>) - #22234

Merged
JukkaL merged 5 commits into
masterfrom
mypyc-list-from-gen
Oct 20, 2026
Merged

JukkaL merged 5 commits into
masterfrom
mypyc-list-from-gen

Conversation

@JukkaL

@JukkaL JukkaL commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

The special case for list() only handled sources
that allow preallocating the result (such as lists and tuples). For other
sources, the generator expression was first compiled into a list, an
iterator was created for it, and list() then copied the items into a new
list. Compile it as a list comprehension in all cases instead.

The special case for list(<generator expression>) only handled sources
that allow preallocating the result (such as lists and tuples). For other
sources, the generator expression was first compiled into a list, an
iterator was created for it, and list() then copied the items into a new
list. Compile it as a list comprehension in all cases instead.
…ents

Specializers that compile a generator expression argument inline (such as
list(), sorted() and str.join()) bypassed the check for unpacking in
comprehensions (Python 3.15+), causing an internal compiler error. Skip
specializers for such calls, so that the generic path reports the error.
@JukkaL
JukkaL merged commit 2ec1257 into master Oct 20, 2026
18 checks passed
@JukkaL
JukkaL deleted the mypyc-list-from-gen branch October 20, 2026 11:46
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