raisefunction 1.0.2__py3-none-any.whl → 1.0.4__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.
- raisefunction/core/__init__.py +14 -21
- raisefunction/tests/__init__.py +4 -0
- raisefunction/tests/test_0.py +20 -10
- {raisefunction-1.0.2.dist-info → raisefunction-1.0.4.dist-info}/METADATA +5 -5
- raisefunction-1.0.4.dist-info/RECORD +9 -0
- {raisefunction-1.0.2.dist-info → raisefunction-1.0.4.dist-info}/WHEEL +1 -1
- raisefunction/tests/test_1.py +0 -17
- raisefunction-1.0.2.dist-info/RECORD +0 -10
- {raisefunction-1.0.2.dist-info → raisefunction-1.0.4.dist-info/licenses}/LICENSE.txt +0 -0
- {raisefunction-1.0.2.dist-info → raisefunction-1.0.4.dist-info}/top_level.txt +0 -0
raisefunction/core/__init__.py
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
from typing import *
|
|
2
2
|
|
|
3
|
-
from overloadable import overloadable
|
|
4
|
-
|
|
5
3
|
__all__ = ["raisefunction"]
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
@overloadable
|
|
9
|
-
def raisefunction(*args: Any, **kwargs: Any) -> int:
|
|
10
|
-
"This function works as dispatcher."
|
|
11
|
-
argc = len(args)
|
|
12
|
-
keys = set(kwargs.keys())
|
|
13
|
-
if argc <= 1 and keys == set():
|
|
14
|
-
return 1
|
|
15
|
-
if argc == 0 and keys == {"exc"}:
|
|
16
|
-
return 1
|
|
17
|
-
return 2
|
|
5
|
+
DEFAULT = object()
|
|
18
6
|
|
|
19
7
|
|
|
20
|
-
@
|
|
21
|
-
def raisefunction(exc: BaseException) -> None:
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
@overload
|
|
9
|
+
def raisefunction(exc: BaseException) -> None: ...
|
|
10
|
+
@overload
|
|
11
|
+
def raisefunction(exc: BaseException, cause: Optional[BaseException]) -> None: ...
|
|
24
12
|
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
def raisefunction(
|
|
15
|
+
exc: BaseException,
|
|
16
|
+
cause: Optional[BaseException] | object = DEFAULT,
|
|
17
|
+
) -> Never:
|
|
18
|
+
"This function raises the given exception."
|
|
19
|
+
if cause is DEFAULT:
|
|
20
|
+
raise exc
|
|
21
|
+
else:
|
|
22
|
+
raise exc from cause
|
raisefunction/tests/__init__.py
CHANGED
|
@@ -5,6 +5,10 @@ __all__ = ["test"]
|
|
|
5
5
|
|
|
6
6
|
def test() -> unittest.TextTestRunner:
|
|
7
7
|
"This function runs all the tests."
|
|
8
|
+
loader: unittest.TestLoader
|
|
9
|
+
tests: unittest.TestSuite
|
|
10
|
+
runner: unittest.TextTestRunner
|
|
11
|
+
result: unittest.TextTestResult
|
|
8
12
|
loader = unittest.TestLoader()
|
|
9
13
|
tests = loader.discover(start_dir="raisefunction.tests")
|
|
10
14
|
runner = unittest.TextTestRunner()
|
raisefunction/tests/test_0.py
CHANGED
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
import unittest
|
|
2
|
+
from typing import *
|
|
2
3
|
|
|
3
4
|
from raisefunction.core import raisefunction
|
|
4
5
|
|
|
6
|
+
__all__ = ["TestRaiseFunction"]
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
class TestRaiseFunction(unittest.TestCase):
|
|
7
|
-
def test_dispatcher_no_arguments(self):
|
|
8
|
-
"
|
|
10
|
+
def test_dispatcher_no_arguments(self: Self) -> None:
|
|
11
|
+
"Test the dispatcher raises a TypeError with no arguments."
|
|
9
12
|
with self.assertRaises(TypeError) as context:
|
|
10
13
|
raisefunction()
|
|
11
14
|
# self.assertIn("requires at least 1 positional argument", str(context.exception))
|
|
12
15
|
|
|
13
|
-
def test_dispatcher_too_many_arguments(self):
|
|
14
|
-
"
|
|
16
|
+
def test_dispatcher_too_many_arguments(self: Self) -> None:
|
|
17
|
+
"Test the dispatcher raises a TypeError with more than 2 arguments."
|
|
15
18
|
with self.assertRaises(TypeError) as context:
|
|
16
19
|
raisefunction(1, 2, 3)
|
|
17
20
|
# self.assertIn("takes at most 2 positional arguments", str(context.exception))
|
|
18
21
|
|
|
19
|
-
def test_raise_single_exception(self):
|
|
20
|
-
"
|
|
22
|
+
def test_raise_single_exception(self: Self) -> None:
|
|
23
|
+
"Test the single exception raising overload."
|
|
21
24
|
with self.assertRaises(ValueError):
|
|
22
25
|
raisefunction(ValueError("Test single exception"))
|
|
23
26
|
|
|
24
|
-
def test_raise_exception_with_cause(self):
|
|
25
|
-
"
|
|
27
|
+
def test_raise_exception_with_cause(self: Self) -> None:
|
|
28
|
+
"Test the exception raising overload with a cause."
|
|
26
29
|
with self.assertRaises(ValueError) as context:
|
|
27
30
|
raisefunction(ValueError("Test exception"), TypeError("Cause exception"))
|
|
28
31
|
self.assertEqual(str(context.exception), "Test exception")
|
|
29
32
|
self.assertIsInstance(context.exception.__cause__, TypeError)
|
|
30
33
|
self.assertEqual(str(context.exception.__cause__), "Cause exception")
|
|
31
34
|
|
|
32
|
-
def test_invalid_arguments_in_overloads(self):
|
|
33
|
-
"
|
|
35
|
+
def test_invalid_arguments_in_overloads(self: Self) -> None:
|
|
36
|
+
"Test invalid argument types raise appropriate errors."
|
|
34
37
|
with self.assertRaises(TypeError):
|
|
35
38
|
raisefunction("not an exception")
|
|
36
39
|
with self.assertRaises(TypeError):
|
|
37
40
|
raisefunction("not an exception", "not a cause")
|
|
38
41
|
|
|
42
|
+
def test_raise_exception_with_cause(self: Self) -> None:
|
|
43
|
+
"Test the exception raising overload with a cause."
|
|
44
|
+
with self.assertRaises(ValueError) as context:
|
|
45
|
+
raisefunction(ValueError("Test exception"), KeyError("Cause exception"))
|
|
46
|
+
self.assertEqual(str(context.exception), "Test exception")
|
|
47
|
+
self.assertIsInstance(context.exception.__cause__, KeyError)
|
|
48
|
+
|
|
39
49
|
|
|
40
50
|
if __name__ == "__main__":
|
|
41
51
|
unittest.main()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: raisefunction
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: This project provides a function that raises errors passed to it.
|
|
5
|
-
Author-email: Johannes <johannes
|
|
5
|
+
Author-email: Johannes <johannes.programming@gmail.com>
|
|
6
6
|
License: The MIT License (MIT)
|
|
7
7
|
|
|
8
8
|
Copyright (c) 2025 Johannes
|
|
@@ -37,10 +37,10 @@ Classifier: Programming Language :: Python
|
|
|
37
37
|
Classifier: Programming Language :: Python :: 3
|
|
38
38
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
39
39
|
Classifier: Typing :: Typed
|
|
40
|
-
Requires-Python: >=3.
|
|
40
|
+
Requires-Python: >=3.11
|
|
41
41
|
Description-Content-Type: text/x-rst
|
|
42
42
|
License-File: LICENSE.txt
|
|
43
|
-
|
|
43
|
+
Dynamic: license-file
|
|
44
44
|
|
|
45
45
|
=============
|
|
46
46
|
raisefunction
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
raisefunction/__init__.py,sha256=0xtTuwb1TPDFx5-GIRBo3WbxvknACp4_AFS5j72-zM0,106
|
|
2
|
+
raisefunction/core/__init__.py,sha256=98IOjpmtKx3bBaOdyhQciGN3EZg1KScioHebOoPhXHE,468
|
|
3
|
+
raisefunction/tests/__init__.py,sha256=NoLlUVKPNjwUUmcc9OcYNqt1RuzVMms-gb8fRb9UjKQ,435
|
|
4
|
+
raisefunction/tests/test_0.py,sha256=wRPxK2wPLckbzrUetSarpB-PIIfz0F5rUK-lYSlnwZs,2247
|
|
5
|
+
raisefunction-1.0.4.dist-info/licenses/LICENSE.txt,sha256=fOh9FHccUt9OcJPBaVJ482GX4yrl_FxCUk9YRZ53JOI,1074
|
|
6
|
+
raisefunction-1.0.4.dist-info/METADATA,sha256=n1YEwzFEHwOqGO7eNviimCa3NB3bnCff2LjAJ29B_LI,2423
|
|
7
|
+
raisefunction-1.0.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
raisefunction-1.0.4.dist-info/top_level.txt,sha256=pf0_UflpIJG0YtRnp7G7pGh9G9AsASCPwHIAlJ7-XZM,14
|
|
9
|
+
raisefunction-1.0.4.dist-info/RECORD,,
|
raisefunction/tests/test_1.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
|
|
3
|
-
from raisefunction.core import raisefunction
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class TestRaiseFunction(unittest.TestCase):
|
|
7
|
-
|
|
8
|
-
def test_raise_exception_with_cause(self):
|
|
9
|
-
"""Test the exception raising overload with a cause."""
|
|
10
|
-
with self.assertRaises(ValueError) as context:
|
|
11
|
-
raisefunction(ValueError("Test exception"), KeyError("Cause exception"))
|
|
12
|
-
self.assertEqual(str(context.exception), "Test exception")
|
|
13
|
-
self.assertIsInstance(context.exception.__cause__, KeyError)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if __name__ == "__main__":
|
|
17
|
-
unittest.main()
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
raisefunction/__init__.py,sha256=0xtTuwb1TPDFx5-GIRBo3WbxvknACp4_AFS5j72-zM0,106
|
|
2
|
-
raisefunction/core/__init__.py,sha256=L-MsExMom1GyFwa9uC9_HObJUojNyl9DntxuSgFrqR0,711
|
|
3
|
-
raisefunction/tests/__init__.py,sha256=FWYTllioFsRhkH-3slxlK8WblMi3y0xGaZRyV3lReKM,301
|
|
4
|
-
raisefunction/tests/test_0.py,sha256=BiY5ibuddz-kK3VIJS3ya-iEgYlwT3H75m7y5w4FC4M,1745
|
|
5
|
-
raisefunction/tests/test_1.py,sha256=OHHiZN1o5LHx93jv_hQ3RFx2rzTg3Un1Apg1dE-3mSI,545
|
|
6
|
-
raisefunction-1.0.2.dist-info/LICENSE.txt,sha256=fOh9FHccUt9OcJPBaVJ482GX4yrl_FxCUk9YRZ53JOI,1074
|
|
7
|
-
raisefunction-1.0.2.dist-info/METADATA,sha256=kswHRDYFCkt6ORH7034kvKLTYgpaTtXfanqDRpMjI9I,2439
|
|
8
|
-
raisefunction-1.0.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
9
|
-
raisefunction-1.0.2.dist-info/top_level.txt,sha256=pf0_UflpIJG0YtRnp7G7pGh9G9AsASCPwHIAlJ7-XZM,14
|
|
10
|
-
raisefunction-1.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|