module_that_can_be_invoked_from_cli module#
Calculate arithmetic expressions from command line.
- class CalculatorType(value)[source]#
Bases:
CustomStrEnumDefine supported calculator types.
- BINARY = 'binary'#
- GENERAL = 'general'#
- pydantic model BinaryInputs[source]#
Bases:
CustomPydanticBaseModelDefine arguments for binary calculator.
- calculator_type#
kind of calculator
- Type:
typing.Literal[CalculatorType.BINARY]
- operator#
arithmetic operator to be used
- Type:
BinaryArithmeticOperator
Show JSON schema
{ "title": "BinaryInputs", "description": "Define arguments for binary calculator.\n\nAttributes\n----------\ncalculator_type : typing.Literal[CalculatorType.BINARY]\n kind of calculator\nfirst_number : float\n first number for the calculation\noperator : BinaryArithmeticOperator\n arithmetic operator to be used\nsecond_number : float\n second number for the calculation", "type": "object", "properties": { "calculator_type": { "const": "binary", "description": "kind of calculator", "title": "Calculator Type" }, "first_number": { "description": "first number for the calculation", "title": "First Number", "type": "number" }, "operator": { "allOf": [ { "$ref": "#/$defs/BinaryArithmeticOperator" } ], "description": "arithmetic operator to be used" }, "second_number": { "description": "second number for the calculation", "title": "Second Number", "type": "number" } }, "$defs": { "BinaryArithmeticOperator": { "description": "Define supported arithmetic operators.", "enum": [ "+", "-", "*", "/" ], "title": "BinaryArithmeticOperator", "type": "string" } }, "additionalProperties": false, "required": [ "calculator_type", "first_number", "operator", "second_number" ] }
- Config:
extra: str = forbid
- Fields:
- field operator: BinaryArithmeticOperator [Required]#
arithmetic operator to be used
- pydantic model GeneralInputs[source]#
Bases:
CustomPydanticBaseModelDefine arguments of general calculator.
- calculator_type#
kind of calculator
- Type:
typing.Literal[CalculatorType.GENERAL]
Show JSON schema
{ "title": "GeneralInputs", "description": "Define arguments of general calculator.\n\nAttributes\n----------\ncalculator_type : typing.Literal[CalculatorType.GENERAL]\n kind of calculator\nexpression : str\n mathematical expression to be evaluated", "type": "object", "properties": { "calculator_type": { "const": "general", "description": "kind of calculator", "title": "Calculator Type" }, "expression": { "description": "mathematical expression to be evaluated", "title": "Expression", "type": "string" } }, "additionalProperties": false, "required": [ "calculator_type", "expression" ] }
- Config:
extra: str = forbid
- Fields:
- pydantic model UserInputs[source]#
Bases:
CustomPydanticBaseModelDefine sub-commands and arguments of CLI calculator.
- inputs#
inputs for the calculator
- Type:
BinaryInputs | GeneralInputs
Show JSON schema
{ "title": "UserInputs", "description": "Define sub-commands and arguments of CLI calculator.\n\nAttributes\n----------\ninputs : BinaryInputs | GeneralInputs\n inputs for the calculator", "type": "object", "properties": { "inputs": { "description": "inputs for the calculator", "discriminator": { "mapping": { "binary": "#/$defs/BinaryInputs", "general": "#/$defs/GeneralInputs" }, "propertyName": "calculator_type" }, "oneOf": [ { "$ref": "#/$defs/BinaryInputs" }, { "$ref": "#/$defs/GeneralInputs" } ], "title": "Inputs" } }, "$defs": { "BinaryArithmeticOperator": { "description": "Define supported arithmetic operators.", "enum": [ "+", "-", "*", "/" ], "title": "BinaryArithmeticOperator", "type": "string" }, "BinaryInputs": { "additionalProperties": false, "description": "Define arguments for binary calculator.\n\nAttributes\n----------\ncalculator_type : typing.Literal[CalculatorType.BINARY]\n kind of calculator\nfirst_number : float\n first number for the calculation\noperator : BinaryArithmeticOperator\n arithmetic operator to be used\nsecond_number : float\n second number for the calculation", "properties": { "calculator_type": { "const": "binary", "description": "kind of calculator", "title": "Calculator Type" }, "first_number": { "description": "first number for the calculation", "title": "First Number", "type": "number" }, "operator": { "allOf": [ { "$ref": "#/$defs/BinaryArithmeticOperator" } ], "description": "arithmetic operator to be used" }, "second_number": { "description": "second number for the calculation", "title": "Second Number", "type": "number" } }, "required": [ "calculator_type", "first_number", "operator", "second_number" ], "title": "BinaryInputs", "type": "object" }, "GeneralInputs": { "additionalProperties": false, "description": "Define arguments of general calculator.\n\nAttributes\n----------\ncalculator_type : typing.Literal[CalculatorType.GENERAL]\n kind of calculator\nexpression : str\n mathematical expression to be evaluated", "properties": { "calculator_type": { "const": "general", "description": "kind of calculator", "title": "Calculator Type" }, "expression": { "description": "mathematical expression to be evaluated", "title": "Expression", "type": "string" } }, "required": [ "calculator_type", "expression" ], "title": "GeneralInputs", "type": "object" } }, "additionalProperties": false, "required": [ "inputs" ] }
- Config:
extra: str = forbid
- Fields:
- field inputs: BinaryInputs | GeneralInputs [Required]#
inputs for the calculator
- capture_user_inputs() UserInputs[source]#
Capture user inputs for arithmetic expression.
- Returns:
captured user inputs
- Return type: