Skip to content

{Async,}ExitStack's close() and aclose() should have an optional exception parameter #137732

@dcolascione

Description

@dcolascione

Feature or enhancement

Proposal:

ExitStack and AsyncExitStack have close and aclose methods, respectively, that finalize all entries in the stack before scope exit would otherwise do it. Right now, close and aclose accept no parameters and all stack entries are finalized as successes --- i.e. a call to __exit__ with no exception information.

It would be useful to add an optional exception parameter to close and aclose that would allow us to explicitly close a stack as if it had failed, e.g. with a synthetic timeout exception. Today, you can do the job by manually invoking __exit__ or __aexit__ on the stack, but .close() is meant to be more ergonomic.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions