Skip to content

[WIP] [DRAFT] Use *Map(... for T in Iter[...]) instead of *[...]#115

Draft
msullivan wants to merge 4 commits intomainfrom
map
Draft

[WIP] [DRAFT] Use *Map(... for T in Iter[...]) instead of *[...]#115
msullivan wants to merge 4 commits intomainfrom
map

Conversation

@msullivan
Copy link
Copy Markdown
Collaborator

This lets us turn maps over Iter[Any] into Any, which I think we
really might want to do.

…ation

Map is a new operator that wraps the comprehension and will eventually
support different semantics (e.g. propagating Any). For now it behaves
identically to the bare list comprehension. Mypy tests for files that
use Map are xfailed until the stubs are updated.
Iter[Any] now returns a generator that raises IterAnyError on first
__next__ (not __iter__, which CPython calls eagerly when constructing a
genexpr -- before Map can wrap it). Map catches IterAnyError via
`yield from` and yields a _UnpackAny sentinel, which callers of
_eval_args short-circuit into typing.Any.
Map.__iter__ now just yields an (_UnpackedMap, _UnpackedMapEnd) pair; the
evaluator drives the wrapped generator inside _eval_args, catches
IterAnyError there, and emits _UnpackAny. The trailing sentinel keeps
Union[*Map(...)] from collapsing to a single arg before _eval_union can
see it. IterAnyError is now a TypeMapError subclass, living entirely
inside the evaluator.

_eval_args iterates the generator one value at a time so that nested
genexprs closing over the outer iteration variable don't all see its
final value. _eval_union now routes through _eval_args too.
Both the _UnpackedMap branch and the plain-arg branch did the same
eval-and-unpack dance; pull it out.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
python-typemap Ready Ready Preview, Comment Apr 17, 2026 4:45am

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.

1 participant