ruff
a46f553d - [ty] Treat generator-expression exceptions as eagerly evaluated (#27735)

Commit
24 days ago
[ty] Treat generator-expression exceptions as eagerly evaluated (#27735) ## Summary Previously, generator expressions were assumed to execute eagerly for name resolution and assignment expressions, but lazily when determining whether exceptions could reach surrounding handlers: ```python def may_raise() -> None: ... caught = False try: ((value := 1, may_raise()) for _ in [0]) except Exception: caught = True reveal_type(value) # int reveal_type(caught) # Previously: Literal[False]; now: bool ``` We now apply the same eager-execution assumption to exception flow, allowing potentially raising operations inside generator expressions to reach enclosing exception handlers. Generator expressions now follow the existing exception-flow behavior of list, set, and dictionary comprehensions.
Author
Parents
Loading