Skip to content

Commit 2f23259

Browse files
authored
Corrected the type annotation for the exception handler callback (#109)
Fixes #97. Also used Python formatting for all code blocks in the README.
1 parent 0c89199 commit 2f23259

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Version history
33

44
This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
55

6+
**UNRELEASED**
7+
8+
- Corrected the type annotation of the exception handler callback to accept a
9+
``BaseExceptionGroup`` instead of ``BaseException``
10+
611
**1.2.0**
712

813
- Added special monkeypatching if `Apport <https://github.com/canonical/apport>`_ has

README.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ containing more matching exceptions.
5454

5555
Thus, the following Python 3.11+ code:
5656

57-
.. code-block:: python3
57+
.. code-block:: python
5858
5959
try:
6060
...
@@ -66,15 +66,15 @@ Thus, the following Python 3.11+ code:
6666
6767
would be written with this backport like this:
6868

69-
.. code-block:: python3
69+
.. code-block:: python
7070
71-
from exceptiongroup import ExceptionGroup, catch
71+
from exceptiongroup import BaseExceptionGroup, catch
7272
73-
def value_key_err_handler(excgroup: ExceptionGroup) -> None:
73+
def value_key_err_handler(excgroup: BaseExceptionGroup) -> None:
7474
for exc in excgroup.exceptions:
7575
print('Caught exception:', type(exc))
7676
77-
def runtime_err_handler(exc: ExceptionGroup) -> None:
77+
def runtime_err_handler(exc: BaseExceptionGroup) -> None:
7878
print('Caught runtime error')
7979
8080
with catch({
@@ -91,7 +91,9 @@ Suppressing exceptions
9191

9292
This library contains a backport of the ``contextlib.suppress()`` context manager from
9393
Python 3.12.1. It allows you to selectively ignore certain exceptions, even when they're
94-
inside exception groups::
94+
inside exception groups:
95+
96+
.. code-block:: python
9597
9698
from exceptiongroup import suppress
9799

src/exceptiongroup/_catch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ._exceptions import BaseExceptionGroup
1212

1313
if TYPE_CHECKING:
14-
_Handler = Callable[[BaseException], Any]
14+
_Handler = Callable[[BaseExceptionGroup[Any]], Any]
1515

1616

1717
class _Catcher:

0 commit comments

Comments
 (0)