zstdlib 0.10.1__tar.gz → 0.10.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zstdlib-0.10.1 → zstdlib-0.10.3}/PKG-INFO +1 -1
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_exc_capture.py +16 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/__init__.py +1 -1
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/exc_capture.py +22 -14
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.1 → zstdlib-0.10.3}/LICENSE +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/README.md +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/pyproject.toml +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/setup.cfg +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/__init__.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/log/base.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_enum.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_io.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/io.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib/singleton.py +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib.egg-info/SOURCES.txt +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.1 → zstdlib-0.10.3}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -19,6 +19,14 @@ class TestLazy(unittest.TestCase):
|
|
|
19
19
|
with self.assertRaises(ValueError), rt.capture():
|
|
20
20
|
raise ValueError()
|
|
21
21
|
self.assertEqual(len(rt.errors), 1)
|
|
22
|
+
# previous
|
|
23
|
+
with rt.capture():
|
|
24
|
+
pass
|
|
25
|
+
self.assertIs(rt.previous, None)
|
|
26
|
+
test_err = RuntimeError("test")
|
|
27
|
+
with rt.capture():
|
|
28
|
+
raise test_err
|
|
29
|
+
self.assertEqual(rt.previous, test_err)
|
|
22
30
|
# capture's exc_t
|
|
23
31
|
rt = ExcCapture(RuntimeError)
|
|
24
32
|
with self.assertRaises(RuntimeError), rt.capture(ValueError):
|
|
@@ -68,6 +76,14 @@ class TestLazy(unittest.TestCase):
|
|
|
68
76
|
_ = ExcDelay("")
|
|
69
77
|
with self.assertRaises(TypeError):
|
|
70
78
|
ExcDelay(RuntimeError) # type: ignore[arg-type]
|
|
79
|
+
# armed
|
|
80
|
+
with ExcDelay("", RuntimeError, armed=False) as capture, capture():
|
|
81
|
+
raise RuntimeError()
|
|
82
|
+
with ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
83
|
+
capture.armed = False
|
|
84
|
+
raise RuntimeError()
|
|
85
|
+
with self.assertRaises(ExceptionGroup), ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
86
|
+
raise RuntimeError()
|
|
71
87
|
|
|
72
88
|
|
|
73
89
|
if __name__ == "__main__":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from contextlib import AbstractContextManager, contextmanager
|
|
2
2
|
from collections.abc import Iterator
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Self
|
|
4
4
|
|
|
5
5
|
__all__ = ("ExcCapture", "ExcDelay")
|
|
6
6
|
|
|
@@ -8,16 +8,10 @@ __all__ = ("ExcCapture", "ExcDelay")
|
|
|
8
8
|
type EXC_T = type[BaseException] | tuple[type[BaseException]]
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class CaptureFType(Protocol):
|
|
12
|
-
"""The type of the capture function (used for type checking)"""
|
|
13
|
-
|
|
14
|
-
def __call__(self, exc_t: EXC_T | None = None) -> AbstractContextManager[None]: ...
|
|
15
|
-
|
|
16
|
-
|
|
17
11
|
class ExcCapture:
|
|
18
12
|
"""A class that exposes a context manager which captures and suppresses any raised exception of a given type / tuple of types"""
|
|
19
13
|
|
|
20
|
-
__slots__ = ("errors", "exc_t")
|
|
14
|
+
__slots__ = ("errors", "exc_t", "previous")
|
|
21
15
|
|
|
22
16
|
def __init__(self, exc_t: EXC_T | None = None) -> None:
|
|
23
17
|
"""
|
|
@@ -25,47 +19,61 @@ class ExcCapture:
|
|
|
25
19
|
msg: The exception group message
|
|
26
20
|
exc_t: The exception type the capture function should capture, if None it must be passed to the capture function directly
|
|
27
21
|
"""
|
|
28
|
-
self.
|
|
22
|
+
self.previous: BaseException | None = None # The result of the last capture() invocation
|
|
29
23
|
self.errors: list[BaseException] = []
|
|
24
|
+
self.exc_t: EXC_T | None = exc_t
|
|
30
25
|
|
|
31
26
|
@contextmanager
|
|
32
27
|
def capture(self, exc_t: EXC_T | None = None) -> Iterator[None]:
|
|
33
|
-
"""
|
|
28
|
+
"""
|
|
29
|
+
Capture and suppress any exception if type/tuple of types exc_t (self.exc_t if None)
|
|
30
|
+
This function sets self.previous on exit
|
|
31
|
+
"""
|
|
34
32
|
exc_t = self.exc_t if exc_t is None else exc_t
|
|
35
33
|
if exc_t is None:
|
|
36
34
|
raise ValueError("No exception type provided here nor during construction")
|
|
37
35
|
try:
|
|
38
36
|
yield
|
|
37
|
+
self.previous = None
|
|
39
38
|
except exc_t as e:
|
|
39
|
+
self.previous = e
|
|
40
40
|
self.errors.append(e)
|
|
41
41
|
|
|
42
|
+
def __call__(self, exc_t: EXC_T | None = None) -> AbstractContextManager[None]:
|
|
43
|
+
"""An alias for .capture"""
|
|
44
|
+
return self.capture(exc_t)
|
|
45
|
+
|
|
42
46
|
|
|
43
47
|
class ExcDelay(ExcCapture):
|
|
44
48
|
"""A context manager subclass of ExcCapture that raises on exit if errors are captured"""
|
|
45
49
|
|
|
46
|
-
__slots__ = ("_msg",)
|
|
50
|
+
__slots__ = ("_msg", "armed")
|
|
47
51
|
|
|
48
52
|
def __init__(
|
|
49
53
|
self,
|
|
50
54
|
msg: str,
|
|
51
55
|
exc_t: type[BaseException] | None = None,
|
|
56
|
+
*,
|
|
57
|
+
armed: bool = True,
|
|
52
58
|
) -> None:
|
|
53
59
|
"""
|
|
54
60
|
Args:
|
|
55
61
|
msg: The exception group message
|
|
56
62
|
exc_t: The exception type the capture function should capture, if None it must be passed to the capture function directly
|
|
63
|
+
armed: If False, do not raise on context exit if self.errors
|
|
57
64
|
"""
|
|
58
65
|
if not isinstance(msg, str):
|
|
59
66
|
raise TypeError(f"Invalid message type: {type(msg)}")
|
|
67
|
+
self.armed: bool = armed
|
|
60
68
|
self._msg: str = msg
|
|
61
69
|
super().__init__(exc_t)
|
|
62
70
|
|
|
63
|
-
def __enter__(self) ->
|
|
71
|
+
def __enter__(self) -> Self:
|
|
64
72
|
"""Return the capture function to use"""
|
|
65
|
-
return self
|
|
73
|
+
return self
|
|
66
74
|
|
|
67
75
|
def __exit__(self, type_: type[BaseException] | None, *_: object) -> None:
|
|
68
76
|
"""Raise an ExceptionGroup (or BaseExceptionGroup depending on exc_t) if self.errors"""
|
|
69
|
-
if type_ is None and self.errors:
|
|
77
|
+
if type_ is None and self.errors and self.armed:
|
|
70
78
|
# Auto-converts to ExceptionGroup if all items are Exceptions
|
|
71
79
|
raise BaseExceptionGroup(self._msg, self.errors)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|