zstdlib 0.10.1__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.
Files changed (38) hide show
  1. {zstdlib-0.10.1 → zstdlib-0.10.2}/PKG-INFO +1 -1
  2. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_exc_capture.py +17 -0
  3. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/__init__.py +1 -1
  4. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/exc_capture.py +15 -5
  5. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib.egg-info/PKG-INFO +1 -1
  6. {zstdlib-0.10.1 → zstdlib-0.10.2}/LICENSE +0 -0
  7. {zstdlib-0.10.1 → zstdlib-0.10.2}/README.md +0 -0
  8. {zstdlib-0.10.1 → zstdlib-0.10.2}/pyproject.toml +0 -0
  9. {zstdlib-0.10.1 → zstdlib-0.10.2}/setup.cfg +0 -0
  10. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/__init__.py +0 -0
  11. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/log/__init__.py +0 -0
  12. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/log/base.py +0 -0
  13. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/log/test_cute.py +0 -0
  14. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/log/test_trace.py +0 -0
  15. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_ansi.py +0 -0
  16. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_enum.py +0 -0
  17. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_frozen.py +0 -0
  18. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_io.py +0 -0
  19. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_lazy.py +0 -0
  20. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_not_set.py +0 -0
  21. {zstdlib-0.10.1 → zstdlib-0.10.2}/tests/test_singleton.py +0 -0
  22. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/ansi.py +0 -0
  23. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/enum.py +0 -0
  24. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/frozen.py +0 -0
  25. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/io.py +0 -0
  26. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/lazy.py +0 -0
  27. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/log/__init__.py +0 -0
  28. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/log/cute.py +0 -0
  29. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/log/trace.py +0 -0
  30. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/macos.py +0 -0
  31. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/not_set.py +0 -0
  32. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/py.typed +0 -0
  33. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/signal_cm.py +0 -0
  34. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib/singleton.py +0 -0
  35. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib.egg-info/SOURCES.txt +0 -0
  36. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib.egg-info/dependency_links.txt +0 -0
  37. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib.egg-info/requires.txt +0 -0
  38. {zstdlib-0.10.1 → zstdlib-0.10.2}/zstdlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zstdlib
3
- Version: 0.10.1
3
+ Version: 0.10.2
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -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,15 @@ 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
+ 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()
71
88
 
72
89
 
73
90
  if __name__ == "__main__":
@@ -1,4 +1,4 @@
1
- __version__ = "0.10.1"
1
+ __version__ = "0.10.2"
2
2
 
3
3
  from .exc_capture import ExcCapture, ExcDelay
4
4
  from .not_set import NotSetType, NotSet
@@ -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,48 @@ 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.exc_t: EXC_T | None = exc_t
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
- """Capture and suppress any exception if type/tuple of types exc_t (self.exc_t if None)"""
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
63
  msg: The exception group message
56
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
  """
58
67
  if not isinstance(msg, str):
59
68
  raise TypeError(f"Invalid message type: {type(msg)}")
69
+ self.armed: bool = armed
60
70
  self._msg: str = msg
61
71
  super().__init__(exc_t)
62
72
 
@@ -66,6 +76,6 @@ class ExcDelay(ExcCapture):
66
76
 
67
77
  def __exit__(self, type_: type[BaseException] | None, *_: object) -> None:
68
78
  """Raise an ExceptionGroup (or BaseExceptionGroup depending on exc_t) if self.errors"""
69
- if type_ is None and self.errors:
79
+ if type_ is None and self.errors and self.armed:
70
80
  # Auto-converts to ExceptionGroup if all items are Exceptions
71
81
  raise BaseExceptionGroup(self._msg, self.errors)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zstdlib
3
- Version: 0.10.1
3
+ Version: 0.10.2
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
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