From ded47eecc2979bad4a6d29adcd43dd058ed82143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Wed, 17 Feb 2021 17:28:58 +0100 Subject: [PATCH] added ExceptionList --- CHANGELOG.md | 3 +++ docs/coding/typing.rst | 2 ++ satella/coding/typing.py | 9 ++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac62f23..2c841962 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,4 @@ # v2.14.41 + +* added `ExceptionList` +* added `terminate_on` for `TerminableThread` diff --git a/docs/coding/typing.rst b/docs/coding/typing.rst index d417848f..e5720192 100644 --- a/docs/coding/typing.rst +++ b/docs/coding/typing.rst @@ -16,6 +16,8 @@ They are as follows: * `Predicate` - a callable that accepts a `T` and returns a bool * `KVTuple` - a tuple of (K, V) * `Comparable` - a class that allows comparison between it's instances +* `ExceptionList` - either a single exception type or a tuple of exception types. + As used by `except` statement and some satella functions. You may use these generics in your classes, eg. diff --git a/satella/coding/typing.py b/satella/coding/typing.py index aa015eb4..ab81ef1e 100644 --- a/satella/coding/typing.py +++ b/satella/coding/typing.py @@ -1,6 +1,11 @@ import typing as tp from abc import ABCMeta, abstractmethod +__all__ = ['Iteratable', 'T', 'U', 'V', 'K', 'Number', 'ExceptionClassType', + 'NoArgCallable', 'Appendable', 'Predicate', 'KVTuple', + 'Comparable', 'ExceptionList'] + + NoneType = None.__class__ T = tp.TypeVar('T') Iteratable = tp.Union[tp.Iterator[T], tp.Iterable[T]] @@ -13,6 +18,7 @@ NoArgCallable = tp.Callable[[], T] Predicate = tp.Callable[[T], bool] ExceptionClassType = tp.Type[Exception] +ExceptionList = tp.Union[ExceptionClassType, tp.Tuple[ExceptionClassType]] class ClassComparable(metaclass=ABCMeta): @@ -42,6 +48,3 @@ class Appendable(Protocol[T]): ... -__all__ = ['Iteratable', 'T', 'U', 'V', 'K', 'Number', 'ExceptionClassType', - 'NoArgCallable', 'Appendable', 'Predicate', 'KVTuple', - 'Comparable'] -- GitLab