Skip to content

Commit

Permalink
Corrected the type annotation for the exception handler callback (#109)
Browse files Browse the repository at this point in the history
Fixes #97.

Also used Python formatting for all code blocks in the README.
  • Loading branch information
agronholm committed Feb 20, 2024
1 parent 0c89199 commit 2f23259
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,11 @@ Version history

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

**UNRELEASED**

- Corrected the type annotation of the exception handler callback to accept a
``BaseExceptionGroup`` instead of ``BaseException``

**1.2.0**

- Added special monkeypatching if `Apport <https://github.com/canonical/apport>`_ has
Expand Down
14 changes: 8 additions & 6 deletions README.rst
Expand Up @@ -54,7 +54,7 @@ containing more matching exceptions.

Thus, the following Python 3.11+ code:

.. code-block:: python3
.. code-block:: python
try:
...
Expand All @@ -66,15 +66,15 @@ Thus, the following Python 3.11+ code:
would be written with this backport like this:

.. code-block:: python3
.. code-block:: python
from exceptiongroup import ExceptionGroup, catch
from exceptiongroup import BaseExceptionGroup, catch
def value_key_err_handler(excgroup: ExceptionGroup) -> None:
def value_key_err_handler(excgroup: BaseExceptionGroup) -> None:
for exc in excgroup.exceptions:
print('Caught exception:', type(exc))
def runtime_err_handler(exc: ExceptionGroup) -> None:
def runtime_err_handler(exc: BaseExceptionGroup) -> None:
print('Caught runtime error')
with catch({
Expand All @@ -91,7 +91,9 @@ Suppressing exceptions

This library contains a backport of the ``contextlib.suppress()`` context manager from
Python 3.12.1. It allows you to selectively ignore certain exceptions, even when they're
inside exception groups::
inside exception groups:

.. code-block:: python
from exceptiongroup import suppress
Expand Down
2 changes: 1 addition & 1 deletion src/exceptiongroup/_catch.py
Expand Up @@ -11,7 +11,7 @@
from ._exceptions import BaseExceptionGroup

if TYPE_CHECKING:
_Handler = Callable[[BaseException], Any]
_Handler = Callable[[BaseExceptionGroup[Any]], Any]


class _Catcher:
Expand Down

0 comments on commit 2f23259

Please sign in to comment.