raisefunction 1.0.3__tar.gz → 1.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: raisefunction
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: This project provides a function that raises errors passed to it.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -40,7 +40,6 @@ Classifier: Typing :: Typed
40
40
  Requires-Python: >=3.11
41
41
  Description-Content-Type: text/x-rst
42
42
  License-File: LICENSE.txt
43
- Requires-Dist: overloadable<2,>=1.0.14
44
43
  Dynamic: license-file
45
44
 
46
45
  =============
@@ -1,7 +1,7 @@
1
1
  [build-system]
2
2
  build-backend = "setuptools.build_meta"
3
3
  requires = [
4
- "setuptools>=61.0",
4
+ "setuptools>=64.0",
5
5
  ]
6
6
 
7
7
  [project]
@@ -19,15 +19,13 @@ classifiers = [
19
19
  "Programming Language :: Python :: 3 :: Only",
20
20
  "Typing :: Typed",
21
21
  ]
22
- dependencies = [
23
- "overloadable>=1.0.14,<2",
24
- ]
22
+ dependencies = []
25
23
  description = "This project provides a function that raises errors passed to it."
26
24
  keywords = []
27
25
  name = "raisefunction"
28
26
  readme = "README.rst"
29
27
  requires-python = ">=3.11"
30
- version = "1.0.3"
28
+ version = "1.0.4"
31
29
 
32
30
  [project.license]
33
31
  file = "LICENSE.txt"
@@ -0,0 +1,22 @@
1
+ from typing import *
2
+
3
+ __all__ = ["raisefunction"]
4
+
5
+ DEFAULT = object()
6
+
7
+
8
+ @overload
9
+ def raisefunction(exc: BaseException) -> None: ...
10
+ @overload
11
+ def raisefunction(exc: BaseException, cause: Optional[BaseException]) -> None: ...
12
+
13
+
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
@@ -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()
@@ -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
- """Test the dispatcher raises a TypeError with no arguments."""
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
- """Test the dispatcher raises a TypeError with more than 2 arguments."""
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
- """Test the single exception raising overload."""
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
- """Test the exception raising overload with a cause."""
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
- """Test invalid argument types raise appropriate errors."""
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: raisefunction
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: This project provides a function that raises errors passed to it.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -40,7 +40,6 @@ Classifier: Typing :: Typed
40
40
  Requires-Python: >=3.11
41
41
  Description-Content-Type: text/x-rst
42
42
  License-File: LICENSE.txt
43
- Requires-Dist: overloadable<2,>=1.0.14
44
43
  Dynamic: license-file
45
44
 
46
45
  =============
@@ -7,9 +7,7 @@ src/raisefunction/__init__.py
7
7
  src/raisefunction.egg-info/PKG-INFO
8
8
  src/raisefunction.egg-info/SOURCES.txt
9
9
  src/raisefunction.egg-info/dependency_links.txt
10
- src/raisefunction.egg-info/requires.txt
11
10
  src/raisefunction.egg-info/top_level.txt
12
11
  src/raisefunction/core/__init__.py
13
12
  src/raisefunction/tests/__init__.py
14
- src/raisefunction/tests/test_0.py
15
- src/raisefunction/tests/test_1.py
13
+ src/raisefunction/tests/test_0.py
@@ -1,29 +0,0 @@
1
- from typing import *
2
-
3
- from overloadable import overloadable
4
-
5
- __all__ = ["raisefunction"]
6
-
7
-
8
- @overloadable
9
- def raisefunction(*args: Any, **kwargs: Any) -> int:
10
- "This function works as dispatcher."
11
- argc: int = len(args)
12
- keys: set = 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
18
-
19
-
20
- @raisefunction.overload(1)
21
- def raisefunction(exc: BaseException) -> None:
22
- "This function raises the given exception."
23
- raise exc
24
-
25
-
26
- @raisefunction.overload(2)
27
- def raisefunction(exc: BaseException, cause: Optional[BaseException]) -> None:
28
- "This function raises the given exception with the given cause."
29
- raise exc from cause
@@ -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 +0,0 @@
1
- overloadable<2,>=1.0.14
File without changes
File without changes
File without changes
File without changes