[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -2,10 +2,13 @@ from __future__ import annotations
import inspect
import sys
from collections.abc import Callable, Iterable, Mapping
from collections.abc import Callable
from collections.abc import Iterable
from collections.abc import Mapping
from contextlib import AbstractContextManager
from types import TracebackType
from typing import TYPE_CHECKING, Any
from typing import Any
from typing import TYPE_CHECKING
if sys.version_info < (3, 11):
from ._exceptions import BaseExceptionGroup
@ -52,7 +55,7 @@ class _Catcher:
if isinstance(exc, BaseExceptionGroup):
excgroup = exc
else:
excgroup = BaseExceptionGroup("", [exc])
excgroup = BaseExceptionGroup('', [exc])
new_exceptions: list[BaseException] = []
for exc_types, handler in self._handler_map.items():
@ -73,8 +76,8 @@ class _Catcher:
else:
if inspect.iscoroutine(result):
raise TypeError(
f"Error trying to handle {matched!r} with {handler!r}. "
"Exception handler must be a sync function."
f'Error trying to handle {matched!r} with {handler!r}. '
'Exception handler must be a sync function.',
) from exc
if not excgroup:
@ -84,7 +87,7 @@ class _Catcher:
if len(new_exceptions) == 1:
return new_exceptions[0]
return BaseExceptionGroup("", new_exceptions)
return BaseExceptionGroup('', new_exceptions)
elif (
excgroup and len(excgroup.exceptions) == 1 and excgroup.exceptions[0] is exc
):
@ -94,43 +97,43 @@ class _Catcher:
def catch(
__handlers: Mapping[type[BaseException] | Iterable[type[BaseException]], _Handler]
__handlers: Mapping[type[BaseException] | Iterable[type[BaseException]], _Handler],
) -> AbstractContextManager[None]:
if not isinstance(__handlers, Mapping):
raise TypeError("the argument must be a mapping")
raise TypeError('the argument must be a mapping')
handler_map: dict[
tuple[type[BaseException], ...], Callable[[BaseExceptionGroup]]
tuple[type[BaseException], ...], Callable[[BaseExceptionGroup]],
] = {}
for type_or_iterable, handler in __handlers.items():
iterable: tuple[type[BaseException]]
if isinstance(type_or_iterable, type) and issubclass(
type_or_iterable, BaseException
type_or_iterable, BaseException,
):
iterable = (type_or_iterable,)
elif isinstance(type_or_iterable, Iterable):
iterable = tuple(type_or_iterable)
else:
raise TypeError(
"each key must be either an exception classes or an iterable thereof"
'each key must be either an exception classes or an iterable thereof',
)
if not callable(handler):
raise TypeError("handlers must be callable")
raise TypeError('handlers must be callable')
for exc_type in iterable:
if not isinstance(exc_type, type) or not issubclass(
exc_type, BaseException
exc_type, BaseException,
):
raise TypeError(
"each key must be either an exception classes or an iterable "
"thereof"
'each key must be either an exception classes or an iterable '
'thereof',
)
if issubclass(exc_type, BaseExceptionGroup):
raise TypeError(
"catching ExceptionGroup with catch() is not allowed. "
"Use except instead."
'catching ExceptionGroup with catch() is not allowed. '
'Use except instead.',
)
handler_map[iterable] = handler