66
77import pydantic
88
9- import package_name_to_import_with
9+ from package_name_to_import_with import (
10+ BinaryArithmeticOperator ,
11+ calculate_results ,
12+ solve_simplification ,
13+ )
1014
1115
1216@enum .unique
@@ -18,23 +22,49 @@ class CalculatorType(str, enum.Enum):
1822
1923
2024class BinaryInputs (pydantic .BaseModel ):
21- """Define arguments for binary calculator."""
25+ """Define arguments for binary calculator.
26+
27+ Attributes
28+ ----------
29+ calculator_type : typing.Literal[CalculatorType.BINARY]
30+ kind of calculator
31+ first_number : float
32+ first number for the calculation
33+ operator : BinaryArithmeticOperator
34+ arithmetic operator to be used
35+ second_number : float
36+ second number for the calculation
37+ """
2238
2339 calculator_type : typing .Literal [CalculatorType .BINARY ]
2440 first_number : float
25- operator : package_name_to_import_with . calculator_sub_package . ArithmeticOperator
41+ operator : BinaryArithmeticOperator
2642 second_number : float
2743
2844
2945class GeneralInputs (pydantic .BaseModel ):
30- """Define arguments of general calculator."""
46+ """Define arguments of general calculator.
47+
48+ Attributes
49+ ----------
50+ calculator_type : typing.Literal[CalculatorType.GENERAL]
51+ kind of calculator
52+ expression : str
53+ mathematical expression to be evaluated
54+ """
3155
3256 calculator_type : typing .Literal [CalculatorType .GENERAL ]
3357 expression : str
3458
3559
3660class UserInputs (pydantic .BaseModel ):
37- """Define sub-commands and arguments of CLI calculator."""
61+ """Define sub-commands and arguments of CLI calculator.
62+
63+ Attributes
64+ ----------
65+ inputs : BinaryInputs | GeneralInputs
66+ inputs for the calculator
67+ """
3868
3969 inputs : BinaryInputs | GeneralInputs = pydantic .Field (discriminator = "calculator_type" )
4070
@@ -63,9 +93,7 @@ def capture_user_inputs() -> UserInputs:
6393
6494 binary_parser .add_argument ("first_number" , type = float , help = "first number" )
6595 binary_parser .add_argument (
66- "operator" ,
67- type = package_name_to_import_with .calculator_sub_package .ArithmeticOperator ,
68- help = "arithmetic operator" ,
96+ "operator" , type = BinaryArithmeticOperator , help = "arithmetic operator"
6997 )
7098 binary_parser .add_argument ("second_number" , type = float , help = "second number" )
7199
@@ -84,13 +112,13 @@ def console_calculator() -> None:
84112 try :
85113 match user_inputs .inputs .calculator_type :
86114 case CalculatorType .BINARY :
87- operation_result = package_name_to_import_with . calculate_results (
115+ operation_result = calculate_results (
88116 user_inputs .inputs .first_number , # type: ignore[union-attr]
89117 user_inputs .inputs .operator , # type: ignore[union-attr]
90118 user_inputs .inputs .second_number , # type: ignore[union-attr]
91119 )
92120 case CalculatorType .GENERAL :
93- operation_result = package_name_to_import_with . solve_simplification (
121+ operation_result = solve_simplification (
94122 user_inputs .inputs .expression # type: ignore[union-attr]
95123 )
96124 case _: # pragma: no cover
0 commit comments