catchlib 1.0.1__py3-none-any.whl → 1.0.3__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
@@ -7,7 +7,6 @@ __all__ = ["Catcher"]
7
7
 
8
8
 
9
9
  class Catcher:
10
-
11
10
  "This class catches exceptions."
12
11
 
13
12
  __slots__ = ("_caught",)
@@ -21,8 +20,8 @@ class Catcher:
21
20
  @contextmanager
22
21
  def catch(self: Self, *args: type[BaseException]) -> Generator[Self, None, None]:
23
22
  "This contextmanager catches exceptions."
24
- self._caught = None
25
23
  exc: BaseException
24
+ self._caught = None
26
25
  try:
27
26
  yield self
28
27
  except args as exc:
@@ -41,7 +40,8 @@ class Catcher:
41
40
  @release.overload(False)
42
41
  def release(self: Self) -> None:
43
42
  "This method raises the caught exception."
44
- exc: BaseException = self.caught
43
+ exc: BaseException
44
+ exc = self.caught
45
45
  self._caught = None
46
46
  if exc is not None:
47
47
  raise exc
@@ -49,7 +49,8 @@ class Catcher:
49
49
  @release.overload(True)
50
50
  def release(self: Self, cause: Optional[BaseException]) -> None:
51
51
  "This method raises the caught exception."
52
- exc: BaseException = self.caught
52
+ exc: BaseException
53
+ exc = self.caught
53
54
  self._caught = None
54
55
  if exc is not None:
55
56
  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
@@ -3,10 +3,13 @@ from typing import *
3
3
 
4
4
  from catchlib.core import Catcher
5
5
 
6
+ __all__ = ["TestCatcher"]
7
+
6
8
 
7
9
  class TestCatcher(unittest.TestCase):
8
10
  def test_captures_matching_exception(self: Self) -> None:
9
- catcher: Catcher = Catcher()
11
+ catcher: Catcher
12
+ catcher = Catcher()
10
13
  with catcher.catch(ValueError):
11
14
  raise ValueError("bad value")
12
15
  self.assertIsNotNone(catcher.caught)
@@ -14,13 +17,15 @@ class TestCatcher(unittest.TestCase):
14
17
  self.assertEqual(str(catcher.caught), "bad value")
15
18
 
16
19
  def test_no_exception_leaves_caught_none(self: Self) -> None:
17
- catcher: Catcher = Catcher()
20
+ catcher: Catcher
21
+ catcher = Catcher()
18
22
  with catcher.catch(ValueError):
19
23
  pass
20
24
  self.assertIsNone(catcher.caught)
21
25
 
22
26
  def test_captures_one_of_multiple_types(self: Self) -> None:
23
- catcher: Catcher = Catcher()
27
+ catcher: Catcher
28
+ catcher = Catcher()
24
29
  with catcher.catch(ValueError, KeyError):
25
30
  raise KeyError("missing")
26
31
  self.assertIsNotNone(catcher.caught)
@@ -32,7 +37,8 @@ class TestCatcher(unittest.TestCase):
32
37
  def test_non_matching_exception_propagates_and_does_not_set_caught(
33
38
  self: Self,
34
39
  ) -> None:
35
- catcher: Catcher = Catcher()
40
+ catcher: Catcher
41
+ catcher = Catcher()
36
42
  with self.assertRaises(ZeroDivisionError):
37
43
  with catcher.catch(ValueError, KeyError):
38
44
  1 / 0 # ZeroDivisionError not in capture set
@@ -40,7 +46,8 @@ class TestCatcher(unittest.TestCase):
40
46
  self.assertIsNone(catcher.caught)
41
47
 
42
48
  def test_reuse_and_reset_semantics(self: Self) -> None:
43
- catcher: Catcher = Catcher()
49
+ catcher: Catcher
50
+ catcher = Catcher()
44
51
 
45
52
  # First, capture an exception
46
53
  with catcher.catch(RuntimeError):
@@ -58,7 +65,8 @@ class TestCatcher(unittest.TestCase):
58
65
  self.assertIsInstance(catcher.caught, TypeError)
59
66
 
60
67
  def test_empty_type_tuple_never_catches(self: Self) -> None:
61
- catcher: Catcher = Catcher()
68
+ catcher: Catcher
69
+ catcher = Catcher()
62
70
  # Passing no types should behave like catching nothing: exception propagates
63
71
  with self.assertRaises(ValueError):
64
72
  with catcher.catch():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: catchlib
3
- Version: 1.0.1
3
+ Version: 1.0.3
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)
@@ -0,0 +1,9 @@
1
+ catchlib/__init__.py,sha256=LmWT7JBQPWFiRLTuaTqgduz9WH_4q2EyEtZMaBLIWe8,57
2
+ catchlib/core/__init__.py,sha256=sIWKb7bjKvyeOAuTfwrM__j17nllYaCLZVQg6ymPwso,1548
3
+ catchlib/tests/__init__.py,sha256=rNCdqp3ppovaIKlKOHLcBqF2-JgrV9wdn8tQF0-nl7c,430
4
+ catchlib/tests/test_0.py,sha256=oJtMbo6oSb3aX0Y5-2ICre3_sEQ-bSlbN2Zb5CAVJc8,2711
5
+ catchlib-1.0.3.dist-info/licenses/LICENSE.txt,sha256=fOh9FHccUt9OcJPBaVJ482GX4yrl_FxCUk9YRZ53JOI,1074
6
+ catchlib-1.0.3.dist-info/METADATA,sha256=HocnXegWOoWCaIJa-_0NM_4Dthi0baeLz48kjtzrpnc,2349
7
+ catchlib-1.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ catchlib-1.0.3.dist-info/top_level.txt,sha256=pZsP_Y2Suk_fAyIQrw4g81DUtgZBRIWzb-5Bk-0jmZs,9
9
+ catchlib-1.0.3.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=3oKcw1izBTbfiuzhR1EFMCsayP9S-lI4qDxYDbGCmCw,1525
3
- catchlib/tests/__init__.py,sha256=F79E9ssYcoufZpYJ4I6XSvZTR0wkvc9r-5K3XpYvXsY,387
4
- catchlib/tests/test_0.py,sha256=3GfPlhQRfGxj5fxKtMd--_HwAeE_7RbuRtrltnPHGDQ,2588
5
- catchlib-1.0.1.dist-info/licenses/LICENSE.txt,sha256=fOh9FHccUt9OcJPBaVJ482GX4yrl_FxCUk9YRZ53JOI,1074
6
- catchlib-1.0.1.dist-info/METADATA,sha256=58OqoKhzKNVqIkOkkhcKuc8HYHjGs_v7HkRZF30QKIE,2349
7
- catchlib-1.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- catchlib-1.0.1.dist-info/top_level.txt,sha256=pZsP_Y2Suk_fAyIQrw4g81DUtgZBRIWzb-5Bk-0jmZs,9
9
- catchlib-1.0.1.dist-info/RECORD,,