Skip to content
This repository was archived by the owner on Apr 10, 2022. It is now read-only.

Atexit #32

Merged
merged 2 commits into from
Feb 19, 2021
Merged
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
27 changes: 20 additions & 7 deletions except_star.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# except*

# Exception Groups and except*

## Abstract

Expand Down Expand Up @@ -43,11 +42,16 @@ unwinds. Several real world use cases are listed below.
issue how to aggregate these errors, particularly when they are different
[[Python issue 29980](https://bugs.python.org/issue29980)].

* **Multiple user callbacks fail.** The pytest library allows users to register
finalizers which are executed at teardown. If more than one of these
finalizers raises an exception, only the first is reported to the user. This
can be improved with `ExceptionGroup`s, as explained in this issue by pytest
developer Ran Benita [[Pytest issue 8217](https://github.com/pytest-dev/pytest/issues/8217)]
* **Multiple user callbacks fail.** Python's `atexit.register()` allows users
to register functions that are called on system exit. If any of them raise
exceptions, only the last one is reraised, but it would be better to reraised
all of them together
[[`atexit` documentation](https://docs.python.org/3/library/atexit.html#atexit.register)].
Similarly, the pytest library allows users to register finalizers which
are executed at teardown. If more than one of these finalizers raises an
exception, only the first is reported to the user. This can be improved with
`ExceptionGroup`s, as explained in this issue by pytest developer Ran Benita
[[Pytest issue 8217](https://github.com/pytest-dev/pytest/issues/8217)]

* **Multiple errors in a complex calculation.** The Hypothesis library performs
automatic bug reduction (simplifying code that demonstrates a bug). In the
Expand Down Expand Up @@ -855,6 +859,11 @@ to be updated.

## How to Teach This

`ExceptionGroup`s and `except*` will be documented as part of the language
standard. Libraries that raise `ExceptionGroup`s such as `asyncio` will need to
specify this in their documentation and clarify which API calls need to be
wrapped with `try-except*` rather than `try-except`.

## Reference Implementation

We developed these concepts (and the examples for this PEP) with
Expand Down Expand Up @@ -1051,6 +1060,10 @@ specified in the same place where we state `T`.

https://bugs.python.org/issue40857

* `atexit` documentation:

https://docs.python.org/3/library/atexit.html#atexit.register

* PyTest issue 8217: Improve reporting when multiple teardowns raise an exception

https://github.com/pytest-dev/pytest/issues/8217
Expand Down