Skip to content

Shouldn't AsyncExitStack.__aexit__ return _ExitT_co? #14384

@bradleyharden

Description

@bradleyharden

Right now, AsyncExitStack.__aexit__ unconditionally returns a bool. However, this in contrast to ExitStack.__exit__, which returns the generic _ExitT_co with a bound of bool | None. Why is that? It looks like the actual implementations in contextlib are nearly identical, so I can't readily explain that decision.

Strictly speaking, I think bool is more correct for both, since the actual return value of both ExitStack and AsyncExitStack is a bool. But I suspect the type hints were structured this way to allow type checkers to determine whether the context manager swallows exceptions or not. That's explicitly the behavior of pyright (see here). If that's the case, why is there a difference between ExitStack and AsyncExitStack here? Is it intentional? Or just an oversight?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions