Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This lets us turn maps over
Iter[Any]intoAny, which I think wereally might want to do.