rapid-roots 0.1.0__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.
File without changes
rapid_roots/py.typed ADDED
File without changes
@@ -0,0 +1,40 @@
1
+ """
2
+ reusable tools for validating and checking enums.
3
+
4
+ Author: Cian Quezon
5
+ """
6
+
7
+ from enum import Enum
8
+ from typing import TypeVar, Union
9
+
10
+ E = TypeVar("E", bound=Enum)
11
+
12
+
13
+ def parse_enum(value: Union[str, E], enum_class: type[E]) -> E:
14
+ """
15
+ returns the enum based on the string input or enum type input
16
+
17
+ Args:
18
+ - value(Union[str, E]) = enum string or type
19
+ - enum(Type[E]) = primary enum
20
+
21
+ Returns:
22
+ - Returns the enum selected
23
+ """
24
+ if isinstance(value, enum_class):
25
+ return value
26
+
27
+ if isinstance(value, str):
28
+ try:
29
+ final_enum = enum_class(value.lower())
30
+ return final_enum
31
+
32
+ except ValueError as err:
33
+ valid_enums = ", ".join([e.value for e in enum_class])
34
+ raise ValueError(
35
+ f"Invalid enum '{value}'. Available are the following: [{valid_enums}]"
36
+ ) from err
37
+
38
+ raise TypeError(
39
+ f"value must be str or {enum_class.__name__}, got {type(value).__name__}"
40
+ )
@@ -0,0 +1,21 @@
1
+ from rapid_roots.solvers._enums import MethodType, SolverName
2
+ from rapid_roots.solvers._solvers import (
3
+ BisectionSolver,
4
+ BrentSolver,
5
+ NewtonRaphsonSolver,
6
+ Solver,
7
+ )
8
+ from rapid_roots.solvers.core import RootSolvers
9
+
10
+ __all__ = [
11
+ "Solver",
12
+ "NewtonRaphsonSolver",
13
+ "BrentSolver",
14
+ "BisectionSolver",
15
+ "MethodType",
16
+ "SolverName",
17
+ "RootSolvers",
18
+ ]
19
+
20
+ __version__ = "0.1.0"
21
+ __author__ = "Cian Quezon"