Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/pyright-internal/src/tests/samples/with7.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,25 @@ def test_multi_typevar_context_manager() -> None:
reveal_type(ctx, expected_text="int")
bar = 1
reveal_type(bar, expected_text="Literal['str', 1]")


class AsyncContextManager(Generic[T]):
async def __aenter__(self) -> Self: ...

async def __aexit__(self, exc_type, exc_val, exc_tb) -> T: ...


async def test_generic_async_context_manager() -> None:
# __aexit__ specializes to bool, so the exception may have been suppressed
# and the body may not have run.
baz = "str"
async with AsyncContextManager[bool]() as ctx:
baz = 1
reveal_type(baz, expected_text="Literal['str', 1]")

# __aexit__ specializes to None, so the exception is never suppressed and
# the entire body must have run.
qux = "str"
async with AsyncContextManager[None]() as ctx:
qux = 1
reveal_type(qux, expected_text="Literal[1]")
Loading