zstdlib 0.10.13__tar.gz → 0.10.14__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.13 → zstdlib-0.10.14}/PKG-INFO +1 -1
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/__init__.py +3 -5
- zstdlib-0.10.14/zstdlib/exc/__init__.py +5 -0
- zstdlib-0.10.13/zstdlib/exc_capture.py → zstdlib-0.10.14/zstdlib/exc/capture.py +4 -4
- zstdlib-0.10.14/zstdlib/exc/pop_frames.py +79 -0
- zstdlib-0.10.14/zstdlib/exc/raise_.py +26 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib.egg-info/SOURCES.txt +4 -2
- zstdlib-0.10.13/tests/test_exc_capture.py +0 -96
- {zstdlib-0.10.13 → zstdlib-0.10.14}/LICENSE +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/README.md +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/pyproject.toml +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/setup.cfg +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/__init__.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/log/base.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_enum.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_hybridmethod.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_io.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_ip_lock.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_keyed_instance.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_prompt.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/tests/test_util.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/hybridmethod.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/io.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/ip_lock.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/keyed_instance.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/prompt.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/singleton.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib/util.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.14}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
__version__ = "0.10.
|
|
1
|
+
__version__ = "0.10.14"
|
|
2
2
|
|
|
3
3
|
from .prompt import prompt_until, prompt_for, yn_prompt
|
|
4
4
|
from .ip_lock import GlobalIPLock, IPLock, RIPLock
|
|
5
|
-
from .exc_capture import ExcCapture, ExcDelay
|
|
6
5
|
from .keyed_instance import KeyedInstance
|
|
7
6
|
from .hybridmethod import hybridmethod
|
|
8
7
|
from .not_set import NotSetType, NotSet
|
|
@@ -11,12 +10,10 @@ from .singleton import Singleton
|
|
|
11
10
|
from .signal_cm import signal_cm
|
|
12
11
|
from .enum import Enum, auto
|
|
13
12
|
from .util import normpath
|
|
14
|
-
from . import macos, lazy, log, io
|
|
13
|
+
from . import macos, lazy, log, exc, io
|
|
15
14
|
|
|
16
15
|
__all__ = (
|
|
17
16
|
"Enum",
|
|
18
|
-
"ExcCapture",
|
|
19
|
-
"ExcDelay",
|
|
20
17
|
"Freezable",
|
|
21
18
|
"GlobalIPLock",
|
|
22
19
|
"IPLock",
|
|
@@ -26,6 +23,7 @@ __all__ = (
|
|
|
26
23
|
"RIPLock",
|
|
27
24
|
"Singleton",
|
|
28
25
|
"auto",
|
|
26
|
+
"exc",
|
|
29
27
|
"frozen",
|
|
30
28
|
"hybridmethod",
|
|
31
29
|
"io",
|
|
@@ -2,13 +2,13 @@ from contextlib import AbstractContextManager, contextmanager
|
|
|
2
2
|
from collections.abc import Callable, Iterator
|
|
3
3
|
from typing import Self
|
|
4
4
|
|
|
5
|
-
__all__ = ("
|
|
5
|
+
__all__ = ("Capture", "Delay")
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
type EXC_T = type[BaseException] | tuple[type[BaseException]]
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class Capture:
|
|
12
12
|
"""A class that exposes a context manager which captures and suppresses any raised exception of a given type / tuple of types"""
|
|
13
13
|
|
|
14
14
|
# In python3.15 use sentinel
|
|
@@ -62,8 +62,8 @@ class ExcCapture:
|
|
|
62
62
|
return self.NoResult
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
class
|
|
66
|
-
"""A context manager subclass of
|
|
65
|
+
class Delay(Capture):
|
|
66
|
+
"""A context manager subclass of Capture that raises on exit if errors are captured"""
|
|
67
67
|
|
|
68
68
|
__slots__ = ("_msg", "armed")
|
|
69
69
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from types import TracebackType
|
|
2
|
+
from typing import Self
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
__all__ = ("PopFrames",)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PopFrames:
|
|
9
|
+
"""
|
|
10
|
+
A context manager used to pop traceback frames from an exception;
|
|
11
|
+
Note that python traceback frames are added as each call exception propgation unwinds the call stack
|
|
12
|
+
Thus you can only pop frames between the frame PopFrames lives in and where the exceptions was raised
|
|
13
|
+
MRO superclasses are not supported
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__slots__ = ("_furthest_n", "_n")
|
|
17
|
+
|
|
18
|
+
def __init__(self, n: int = 0, *, furthest_n: int = 0) -> None:
|
|
19
|
+
self._validate(n, furthest_n)
|
|
20
|
+
self._furthest_n: int = furthest_n
|
|
21
|
+
self._n = n
|
|
22
|
+
|
|
23
|
+
def __enter__(self) -> Self:
|
|
24
|
+
return self
|
|
25
|
+
|
|
26
|
+
def __exit__(
|
|
27
|
+
self, _: type[BaseException] | None, exc: BaseException | None, _2: TracebackType | None
|
|
28
|
+
) -> None:
|
|
29
|
+
if isinstance(exc, BaseException):
|
|
30
|
+
self.modify(exc, self._n, furthest_n=self._furthest_n)
|
|
31
|
+
elif exc is not None:
|
|
32
|
+
raise TypeError("exc is not a BaseException | None")
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def modify(cls, exc: BaseException, n: int, furthest_n: int = 0) -> None:
|
|
36
|
+
"""Modify the traceback frames of exc; removes the n most recently entered frames
|
|
37
|
+
If foo calls bar calls baz which raises, n=2 removes (baz, raise)
|
|
38
|
+
from the traceback and furthest_n=1 removes foo from the traceback
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
exc: The exception to modify
|
|
42
|
+
n: The number of frames to remove, referse to the most recently entered frames
|
|
43
|
+
furthest_n: The number of frames to remove, referse to the least recently entered frames
|
|
44
|
+
"""
|
|
45
|
+
cls._validate(n, furthest_n)
|
|
46
|
+
if not isinstance(exc, BaseException):
|
|
47
|
+
raise TypeError("exc is not a BaseException")
|
|
48
|
+
if n == furthest_n == 0:
|
|
49
|
+
return
|
|
50
|
+
# Record the old traceback
|
|
51
|
+
frames: list[TracebackType] = []
|
|
52
|
+
tb = exc.__traceback__
|
|
53
|
+
while tb is not None:
|
|
54
|
+
frames.append(tb)
|
|
55
|
+
tb = tb.tb_next
|
|
56
|
+
# Install the new traceback
|
|
57
|
+
new: TracebackType | None = None
|
|
58
|
+
for f in reversed(frames[furthest_n if furthest_n else None : -n if n else None]):
|
|
59
|
+
new = TracebackType(new, f.tb_frame, f.tb_lasti, f.tb_lineno)
|
|
60
|
+
exc.__traceback__ = new
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def active(cls, n: int = 0, *, reraise: bool, furthest_n: int = 0) -> None:
|
|
64
|
+
"""Remove traceback frames from an active exception, will reraise unless False"""
|
|
65
|
+
e = sys.exc_info()
|
|
66
|
+
if e[0] is None:
|
|
67
|
+
raise RuntimeError("No active exception")
|
|
68
|
+
cls.modify(e[1], n, furthest_n=furthest_n)
|
|
69
|
+
if reraise:
|
|
70
|
+
raise # noqa: PLE0704 # pylint: disable=misplaced-bare-raise
|
|
71
|
+
|
|
72
|
+
# Private helpers
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def _validate(n: int, furthest_n: int) -> None:
|
|
76
|
+
if not isinstance(n, int) or not isinstance(furthest_n, int):
|
|
77
|
+
raise TypeError("Number of frames to pop must be type int")
|
|
78
|
+
if n < 0 or furthest_n < 0:
|
|
79
|
+
raise ValueError("May not pop a negative number of frames")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import Never
|
|
3
|
+
|
|
4
|
+
from ..not_set import NotSetType, NotSet
|
|
5
|
+
from .pop_frames import PopFrames
|
|
6
|
+
|
|
7
|
+
__all__ = ("raise_",)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def raise_[**P, R: BaseException](
|
|
11
|
+
e: BaseException,
|
|
12
|
+
from_: Callable[P, R] | R | None | NotSetType = NotSet,
|
|
13
|
+
/,
|
|
14
|
+
*args: P.args,
|
|
15
|
+
**kwargs: P.kwargs,
|
|
16
|
+
) -> Never:
|
|
17
|
+
"""Raise e from from_; if from_ isn't an exception, from_=from_(*args, **kwargs)"""
|
|
18
|
+
if not isinstance(from_, BaseException | None | NotSetType):
|
|
19
|
+
if not callable(from_):
|
|
20
|
+
raise TypeError("from_ must be callable")
|
|
21
|
+
from_ = from_(*args, **kwargs)
|
|
22
|
+
with PopFrames(1):
|
|
23
|
+
if from_ is NotSet:
|
|
24
|
+
raise e
|
|
25
|
+
assert isinstance(from_, BaseException | None)
|
|
26
|
+
raise e from from_
|
|
@@ -4,7 +4,6 @@ pyproject.toml
|
|
|
4
4
|
tests/__init__.py
|
|
5
5
|
tests/test_ansi.py
|
|
6
6
|
tests/test_enum.py
|
|
7
|
-
tests/test_exc_capture.py
|
|
8
7
|
tests/test_frozen.py
|
|
9
8
|
tests/test_hybridmethod.py
|
|
10
9
|
tests/test_io.py
|
|
@@ -22,7 +21,6 @@ tests/log/test_trace.py
|
|
|
22
21
|
zstdlib/__init__.py
|
|
23
22
|
zstdlib/ansi.py
|
|
24
23
|
zstdlib/enum.py
|
|
25
|
-
zstdlib/exc_capture.py
|
|
26
24
|
zstdlib/frozen.py
|
|
27
25
|
zstdlib/hybridmethod.py
|
|
28
26
|
zstdlib/io.py
|
|
@@ -41,6 +39,10 @@ zstdlib.egg-info/SOURCES.txt
|
|
|
41
39
|
zstdlib.egg-info/dependency_links.txt
|
|
42
40
|
zstdlib.egg-info/requires.txt
|
|
43
41
|
zstdlib.egg-info/top_level.txt
|
|
42
|
+
zstdlib/exc/__init__.py
|
|
43
|
+
zstdlib/exc/capture.py
|
|
44
|
+
zstdlib/exc/pop_frames.py
|
|
45
|
+
zstdlib/exc/raise_.py
|
|
44
46
|
zstdlib/log/__init__.py
|
|
45
47
|
zstdlib/log/cute.py
|
|
46
48
|
zstdlib/log/trace.py
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
|
2
|
-
import unittest
|
|
3
|
-
|
|
4
|
-
from zstdlib import ExcCapture, ExcDelay
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class TestLazy(unittest.TestCase):
|
|
8
|
-
|
|
9
|
-
def test_capture(self) -> None:
|
|
10
|
-
# Capture nothing
|
|
11
|
-
rt = ExcCapture(RuntimeError)
|
|
12
|
-
with rt.capture():
|
|
13
|
-
pass
|
|
14
|
-
self.assertEqual(len(rt.errors), 0)
|
|
15
|
-
# Capture only Runtime
|
|
16
|
-
with rt.capture():
|
|
17
|
-
raise RuntimeError()
|
|
18
|
-
self.assertEqual(len(rt.errors), 1)
|
|
19
|
-
with self.assertRaises(ValueError), rt.capture():
|
|
20
|
-
raise ValueError()
|
|
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)
|
|
30
|
-
# capture's exc_t
|
|
31
|
-
rt = ExcCapture(RuntimeError)
|
|
32
|
-
with self.assertRaises(RuntimeError), rt.capture(ValueError):
|
|
33
|
-
raise RuntimeError()
|
|
34
|
-
self.assertEqual(len(rt.errors), 0)
|
|
35
|
-
with rt.capture(ValueError):
|
|
36
|
-
raise ValueError()
|
|
37
|
-
self.assertEqual(len(rt.errors), 1)
|
|
38
|
-
del rt
|
|
39
|
-
# exc_t = None
|
|
40
|
-
non = ExcCapture()
|
|
41
|
-
with self.assertRaises(RuntimeError), non.capture(ValueError):
|
|
42
|
-
raise RuntimeError()
|
|
43
|
-
self.assertEqual(len(non.errors), 0)
|
|
44
|
-
with self.assertRaises(ValueError), non.capture():
|
|
45
|
-
pass
|
|
46
|
-
self.assertEqual(len(non.errors), 0)
|
|
47
|
-
with non.capture(RuntimeError):
|
|
48
|
-
raise RuntimeError()
|
|
49
|
-
self.assertEqual(len(non.errors), 1)
|
|
50
|
-
# run_fn
|
|
51
|
-
ke = ExcCapture(KeyError)
|
|
52
|
-
self.assertEqual(ke.run_fn({0: 5}.__getitem__, 0), 5)
|
|
53
|
-
self.assertEqual(len(ke.errors), 0)
|
|
54
|
-
self.assertIs(ke.run_fn({}.__getitem__, 0), ke.NoResult)
|
|
55
|
-
self.assertEqual(len(ke.errors), 1)
|
|
56
|
-
|
|
57
|
-
def test_delay(self) -> None:
|
|
58
|
-
# No raise
|
|
59
|
-
with ExcDelay("msg", RuntimeError) as capture, capture():
|
|
60
|
-
pass
|
|
61
|
-
# Raise
|
|
62
|
-
ed = ExcDelay("msg", RuntimeError)
|
|
63
|
-
try:
|
|
64
|
-
with ed as capture:
|
|
65
|
-
with capture():
|
|
66
|
-
raise RuntimeError()
|
|
67
|
-
with capture():
|
|
68
|
-
raise RuntimeError()
|
|
69
|
-
self.assertTrue(False)
|
|
70
|
-
except BaseExceptionGroup as grp:
|
|
71
|
-
self.assertIsInstance(grp, ExceptionGroup) # Test auto-conversion
|
|
72
|
-
self.assertEqual(len(grp.exceptions), 2)
|
|
73
|
-
self.assertEqual(len(ed.errors), 2)
|
|
74
|
-
# No block error
|
|
75
|
-
with self.assertRaises(ValueError), ExcDelay("msg", RuntimeError) as capture, capture():
|
|
76
|
-
raise ValueError()
|
|
77
|
-
with self.assertRaises(ValueError), ExcDelay("msg", RuntimeError) as capture:
|
|
78
|
-
with capture():
|
|
79
|
-
raise RuntimeError()
|
|
80
|
-
raise ValueError()
|
|
81
|
-
# msg
|
|
82
|
-
_ = ExcDelay("")
|
|
83
|
-
with self.assertRaises(TypeError):
|
|
84
|
-
ExcDelay(RuntimeError) # type: ignore[arg-type]
|
|
85
|
-
# armed
|
|
86
|
-
with ExcDelay("", RuntimeError, armed=False) as capture, capture():
|
|
87
|
-
raise RuntimeError()
|
|
88
|
-
with ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
89
|
-
capture.armed = False
|
|
90
|
-
raise RuntimeError()
|
|
91
|
-
with self.assertRaises(ExceptionGroup), ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
92
|
-
raise RuntimeError()
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if __name__ == "__main__":
|
|
96
|
-
unittest.main()
|
|
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
|
|
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
|