Skip to content

[mypyc] Evaluate args in correct order when builtin takes a genexpr - #22214

Merged
JukkaL merged 2 commits into
masterfrom
mypyc-gen-eval-order
Oct 16, 2026
Merged

JukkaL merged 2 commits into
masterfrom
mypyc-gen-eval-order

Conversation

@JukkaL

@JukkaL JukkaL commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

When a generator expression is passed to sum(), min() or another builtin that mypyc has special handling for, match CPython's order of evaluation.

When a generator expression is passed to sum(), min() or another
builtin that mypyc has special handling for, match CPython's order of
evaluation.
Comment on lines +75 to +89
try:
sum((elt(x) for x in it()), fail())
except ValueError:
pass
check(["iterable", "fail"])
try:
next((elt(x) for x in it()), fail())
except ValueError:
pass
check(["iterable", "fail"])
try:
max((elt(x) for x in it()), key=fail())
except ValueError:
pass
check(["iterable", "fail"])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use assertRaises here? theoretically this could pass without raising.

@JukkaL
JukkaL merged commit defbc8d into master Oct 16, 2026
18 checks passed
@JukkaL
JukkaL deleted the mypyc-gen-eval-order branch October 16, 2026 15:03
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