catchlib 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl

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.
catchlib/core/__init__.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from contextlib import contextmanager
2
2
  from typing import *
3
3
 
4
+ from overloadable import Overloadable
5
+
4
6
  __all__ = ["Catcher"]
5
7
 
6
8
 
7
9
  class Catcher:
8
-
9
10
  "This class catches exceptions."
10
11
 
11
12
  __slots__ = ("_caught",)
@@ -30,3 +31,24 @@ class Catcher:
30
31
  def caught(self: Self) -> Optional[BaseException]:
31
32
  "This property stores the caught exception."
32
33
  return self._caught
34
+
35
+ @Overloadable
36
+ def release(self: Self, *args: Any, **kwargs: Any) -> bool:
37
+ "This method raises the caught exception."
38
+ return bool(len(args) + len(kwargs))
39
+
40
+ @release.overload(False)
41
+ def release(self: Self) -> None:
42
+ "This method raises the caught exception."
43
+ exc: BaseException = self.caught
44
+ self._caught = None
45
+ if exc is not None:
46
+ raise exc
47
+
48
+ @release.overload(True)
49
+ def release(self: Self, cause: Optional[BaseException]) -> None:
50
+ "This method raises the caught exception."
51
+ exc: BaseException = self.caught
52
+ self._caught = None
53
+ if exc is not None:
54
+ raise exc from cause
@@ -5,8 +5,12 @@ __all__ = ["test"]
5
5
 
6
6
  def test() -> unittest.TextTestRunner:
7
7
  "This function runs all the tests."
8
- loader: unittest.TestLoader = unittest.TestLoader()
9
- tests: unittest.TestSuite = loader.discover(start_dir="catchlib.tests")
10
- runner: unittest.TextTestRunner = unittest.TextTestRunner()
11
- result: unittest.TextTestResult = runner.run(tests)
8
+ loader: unittest.TestLoader
9
+ tests: unittest.TestSuite
10
+ runner: unittest.TextTestRunner
11
+ result: unittest.TextTestResult
12
+ loader = unittest.TestLoader()
13
+ tests = loader.discover(start_dir="catchlib.tests")
14
+ runner = unittest.TextTestRunner()
15
+ result = runner.run(tests)
12
16
  return result
catchlib/tests/test_0.py CHANGED
@@ -6,7 +6,8 @@ from catchlib.core import Catcher
6
6
 
7
7
  class TestCatcher(unittest.TestCase):
8
8
  def test_captures_matching_exception(self: Self) -> None:
9
- catcher: Catcher = Catcher()
9
+ catcher: Catcher
10
+ catcher = Catcher()
10
11
  with catcher.catch(ValueError):
11
12
  raise ValueError("bad value")
12
13
  self.assertIsNotNone(catcher.caught)
@@ -14,13 +15,15 @@ class TestCatcher(unittest.TestCase):
14
15
  self.assertEqual(str(catcher.caught), "bad value")
15
16
 
16
17
  def test_no_exception_leaves_caught_none(self: Self) -> None:
17
- catcher: Catcher = Catcher()
18
+ catcher: Catcher
19
+ catcher = Catcher()
18
20
  with catcher.catch(ValueError):
19
21
  pass
20
22
  self.assertIsNone(catcher.caught)
21
23
 
22
24
  def test_captures_one_of_multiple_types(self: Self) -> None:
23
- catcher: Catcher = Catcher()
25
+ catcher: Catcher
26
+ catcher = Catcher()
24
27
  with catcher.catch(ValueError, KeyError):
25
28
  raise KeyError("missing")
26
29
  self.assertIsNotNone(catcher.caught)
@@ -32,7 +35,8 @@ class TestCatcher(unittest.TestCase):
32
35
  def test_non_matching_exception_propagates_and_does_not_set_caught(
33
36
  self: Self,
34
37
  ) -> None:
35
- catcher: Catcher = Catcher()
38
+ catcher: Catcher
39
+ catcher = Catcher()
36
40
  with self.assertRaises(ZeroDivisionError):
37
41
  with catcher.catch(ValueError, KeyError):
38
42
  1 / 0 # ZeroDivisionError not in capture set
@@ -40,7 +44,8 @@ class TestCatcher(unittest.TestCase):
40
44
  self.assertIsNone(catcher.caught)
41
45
 
42
46
  def test_reuse_and_reset_semantics(self: Self) -> None:
43
- catcher: Catcher = Catcher()
47
+ catcher: Catcher
48
+ catcher = Catcher()
44
49
 
45
50
  # First, capture an exception
46
51
  with catcher.catch(RuntimeError):
@@ -58,7 +63,8 @@ class TestCatcher(unittest.TestCase):
58
63
  self.assertIsInstance(catcher.caught, TypeError)
59
64
 
60
65
  def test_empty_type_tuple_never_catches(self: Self) -> None:
61
- catcher: Catcher = Catcher()
66
+ catcher: Catcher
67
+ catcher = Catcher()
62
68
  # Passing no types should behave like catching nothing: exception propagates
63
69
  with self.assertRaises(ValueError):
64
70
  with catcher.catch():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: catchlib
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: This project allows to catch exceptions easily.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -39,6 +39,7 @@ Classifier: Typing :: Typed
39
39
  Requires-Python: >=3.11
40
40
  Description-Content-Type: text/x-rst
41
41
  License-File: LICENSE.txt
42
+ Requires-Dist: overloadable<2,>=1.0.9
42
43
  Dynamic: license-file
43
44
 
44
45
  ========
@@ -0,0 +1,9 @@
1
+ catchlib/__init__.py,sha256=LmWT7JBQPWFiRLTuaTqgduz9WH_4q2EyEtZMaBLIWe8,57
2
+ catchlib/core/__init__.py,sha256=duXNKcfqWK1rh7mWO9zSdtiJYDFxwpcTrjHQZUk7yPk,1524
3
+ catchlib/tests/__init__.py,sha256=rNCdqp3ppovaIKlKOHLcBqF2-JgrV9wdn8tQF0-nl7c,430
4
+ catchlib/tests/test_0.py,sha256=AyTakeyPgVf73ijJifEtN3jls8cJEhEEhEug9lpOTfk,2684
5
+ catchlib-1.0.2.dist-info/licenses/LICENSE.txt,sha256=fOh9FHccUt9OcJPBaVJ482GX4yrl_FxCUk9YRZ53JOI,1074
6
+ catchlib-1.0.2.dist-info/METADATA,sha256=hii-Jp9MAoLr_MnrPLjT1UIaj8Zcl_xyCW0j0uf0t5o,2349
7
+ catchlib-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ catchlib-1.0.2.dist-info/top_level.txt,sha256=pZsP_Y2Suk_fAyIQrw4g81DUtgZBRIWzb-5Bk-0jmZs,9
9
+ catchlib-1.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,9 +0,0 @@
1
- catchlib/__init__.py,sha256=LmWT7JBQPWFiRLTuaTqgduz9WH_4q2EyEtZMaBLIWe8,57
2
- catchlib/core/__init__.py,sha256=RGJlPffKlyWeES0noN2qHrJeDXNXv0QVLNpk-Fe_jG8,791
3
- catchlib/tests/__init__.py,sha256=F79E9ssYcoufZpYJ4I6XSvZTR0wkvc9r-5K3XpYvXsY,387
4
- catchlib/tests/test_0.py,sha256=3GfPlhQRfGxj5fxKtMd--_HwAeE_7RbuRtrltnPHGDQ,2588
5
- catchlib-1.0.0.dist-info/licenses/LICENSE.txt,sha256=fOh9FHccUt9OcJPBaVJ482GX4yrl_FxCUk9YRZ53JOI,1074
6
- catchlib-1.0.0.dist-info/METADATA,sha256=U_agBbPRK5aLHGgzH5qGaGg1uuUyIDZOgtfLsDEpd0g,2311
7
- catchlib-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- catchlib-1.0.0.dist-info/top_level.txt,sha256=pZsP_Y2Suk_fAyIQrw4g81DUtgZBRIWzb-5Bk-0jmZs,9
9
- catchlib-1.0.0.dist-info/RECORD,,