zstdlib 0.10.0__tar.gz → 0.10.2__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.0 → zstdlib-0.10.2}/PKG-INFO +1 -1
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_exc_capture.py +21 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/__init__.py +1 -1
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/exc_capture.py +19 -7
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.0 → zstdlib-0.10.2}/LICENSE +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/README.md +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/pyproject.toml +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/setup.cfg +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/__init__.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/log/base.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_enum.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_io.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/io.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib/singleton.py +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib.egg-info/SOURCES.txt +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.0 → zstdlib-0.10.2}/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):
|
|
@@ -64,6 +72,19 @@ class TestLazy(unittest.TestCase):
|
|
|
64
72
|
with capture():
|
|
65
73
|
raise RuntimeError()
|
|
66
74
|
raise ValueError()
|
|
75
|
+
# msg
|
|
76
|
+
_ = ExcDelay("")
|
|
77
|
+
with self.assertRaises(TypeError):
|
|
78
|
+
ExcDelay(RuntimeError) # type: ignore[arg-type]
|
|
79
|
+
# armed
|
|
80
|
+
with ExcDelay("", RuntimeError, armed=False) as capture, capture():
|
|
81
|
+
raise RuntimeError()
|
|
82
|
+
ed = ExcDelay("", RuntimeError, armed=True)
|
|
83
|
+
with ed as capture, capture():
|
|
84
|
+
ed.armed = False
|
|
85
|
+
raise RuntimeError()
|
|
86
|
+
with self.assertRaises(ExceptionGroup), ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
87
|
+
raise RuntimeError()
|
|
67
88
|
|
|
68
89
|
|
|
69
90
|
if __name__ == "__main__":
|
|
@@ -17,7 +17,7 @@ class CaptureFType(Protocol):
|
|
|
17
17
|
class ExcCapture:
|
|
18
18
|
"""A class that exposes a context manager which captures and suppresses any raised exception of a given type / tuple of types"""
|
|
19
19
|
|
|
20
|
-
__slots__ = ("errors", "exc_t")
|
|
20
|
+
__slots__ = ("errors", "exc_t", "previous")
|
|
21
21
|
|
|
22
22
|
def __init__(self, exc_t: EXC_T | None = None) -> None:
|
|
23
23
|
"""
|
|
@@ -25,38 +25,50 @@ class ExcCapture:
|
|
|
25
25
|
msg: The exception group message
|
|
26
26
|
exc_t: The exception type the capture function should capture, if None it must be passed to the capture function directly
|
|
27
27
|
"""
|
|
28
|
-
self.
|
|
28
|
+
self.previous: BaseException | None = None # The result of the last capture() invocation
|
|
29
29
|
self.errors: list[BaseException] = []
|
|
30
|
+
self.exc_t: EXC_T | None = exc_t
|
|
30
31
|
|
|
31
32
|
@contextmanager
|
|
32
33
|
def capture(self, exc_t: EXC_T | None = None) -> Iterator[None]:
|
|
33
|
-
"""
|
|
34
|
+
"""
|
|
35
|
+
Capture and suppress any exception if type/tuple of types exc_t (self.exc_t if None)
|
|
36
|
+
This function sets self.previous on exit
|
|
37
|
+
"""
|
|
34
38
|
exc_t = self.exc_t if exc_t is None else exc_t
|
|
35
39
|
if exc_t is None:
|
|
36
40
|
raise ValueError("No exception type provided here nor during construction")
|
|
37
41
|
try:
|
|
38
42
|
yield
|
|
43
|
+
self.previous = None
|
|
39
44
|
except exc_t as e:
|
|
45
|
+
self.previous = e
|
|
40
46
|
self.errors.append(e)
|
|
41
47
|
|
|
42
48
|
|
|
43
49
|
class ExcDelay(ExcCapture):
|
|
44
50
|
"""A context manager subclass of ExcCapture that raises on exit if errors are captured"""
|
|
45
51
|
|
|
46
|
-
__slots__ = ("_msg",)
|
|
52
|
+
__slots__ = ("_msg", "armed")
|
|
47
53
|
|
|
48
54
|
def __init__(
|
|
49
55
|
self,
|
|
50
56
|
msg: str,
|
|
51
57
|
exc_t: type[BaseException] | None = None,
|
|
58
|
+
*,
|
|
59
|
+
armed: bool = True,
|
|
52
60
|
) -> None:
|
|
53
61
|
"""
|
|
54
62
|
Args:
|
|
55
|
-
exc_t: The exception type the capture function should capture, if None it must be passed to the capture function directly
|
|
56
63
|
msg: The exception group message
|
|
64
|
+
exc_t: The exception type the capture function should capture, if None it must be passed to the capture function directly
|
|
65
|
+
armed: If False, do not raise on context exit if self.errors
|
|
57
66
|
"""
|
|
67
|
+
if not isinstance(msg, str):
|
|
68
|
+
raise TypeError(f"Invalid message type: {type(msg)}")
|
|
69
|
+
self.armed: bool = armed
|
|
70
|
+
self._msg: str = msg
|
|
58
71
|
super().__init__(exc_t)
|
|
59
|
-
self._msg = msg
|
|
60
72
|
|
|
61
73
|
def __enter__(self) -> CaptureFType:
|
|
62
74
|
"""Return the capture function to use"""
|
|
@@ -64,6 +76,6 @@ class ExcDelay(ExcCapture):
|
|
|
64
76
|
|
|
65
77
|
def __exit__(self, type_: type[BaseException] | None, *_: object) -> None:
|
|
66
78
|
"""Raise an ExceptionGroup (or BaseExceptionGroup depending on exc_t) if self.errors"""
|
|
67
|
-
if type_ is None and self.errors:
|
|
79
|
+
if type_ is None and self.errors and self.armed:
|
|
68
80
|
# Auto-converts to ExceptionGroup if all items are Exceptions
|
|
69
81
|
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
|