raisefunction 1.0.1__tar.gz → 1.0.2__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.2
2
2
  Name: raisefunction
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: This project provides a function that raises errors passed to it.
5
5
  Author-email: Johannes <johannes-programming@mailfence.com>
6
6
  License: The MIT License (MIT)
@@ -27,7 +27,7 @@ keywords = []
27
27
  name = "raisefunction"
28
28
  readme = "README.rst"
29
29
  requires-python = ">=3.8"
30
- version = "1.0.1"
30
+ version = "1.0.2"
31
31
 
32
32
  [project.license]
33
33
  file = "LICENSE.txt"
@@ -6,26 +6,24 @@ __all__ = ["raisefunction"]
6
6
 
7
7
 
8
8
  @overloadable
9
- def raisefunction(*args: Any) -> int:
9
+ def raisefunction(*args: Any, **kwargs: Any) -> int:
10
10
  "This function works as dispatcher."
11
- if len(args) < 1:
12
- raise TypeError(
13
- "A raise statement requires at least 1 positional argument (0 given)."
14
- )
15
- if len(args) > 2:
16
- raise TypeError(
17
- "An assertion takes at most 2 positional arguments (%s given)." % len(args)
18
- )
19
- return len(args)
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
20
18
 
21
19
 
22
20
  @raisefunction.overload(1)
23
- def raisefunction(exc: BaseException, /) -> None:
21
+ def raisefunction(exc: BaseException) -> None:
24
22
  "This function raises the given exception."
25
23
  raise exc
26
24
 
27
25
 
28
26
  @raisefunction.overload(2)
29
- def raisefunction(exc: BaseException, cause: Optional[BaseException], /) -> None:
27
+ def raisefunction(exc: BaseException, cause: Optional[BaseException]) -> None:
30
28
  "This function raises the given exception with the given cause."
31
29
  raise exc from cause
@@ -8,13 +8,13 @@ class TestRaiseFunction(unittest.TestCase):
8
8
  """Test the dispatcher raises a TypeError with no arguments."""
9
9
  with self.assertRaises(TypeError) as context:
10
10
  raisefunction()
11
- self.assertIn("requires at least 1 positional argument", str(context.exception))
11
+ # self.assertIn("requires at least 1 positional argument", str(context.exception))
12
12
 
13
13
  def test_dispatcher_too_many_arguments(self):
14
14
  """Test the dispatcher raises a TypeError with more than 2 arguments."""
15
15
  with self.assertRaises(TypeError) as context:
16
16
  raisefunction(1, 2, 3)
17
- self.assertIn("takes at most 2 positional arguments", str(context.exception))
17
+ # self.assertIn("takes at most 2 positional arguments", str(context.exception))
18
18
 
19
19
  def test_raise_single_exception(self):
20
20
  """Test the single exception raising overload."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: raisefunction
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: This project provides a function that raises errors passed to it.
5
5
  Author-email: Johannes <johannes-programming@mailfence.com>
6
6
  License: The MIT License (MIT)
File without changes
File without changes
File without changes
File without changes