Skip to content

lib

Core functionality of fair-python-cookiecutter-demo.

This module can be used directly, or the functionality can be exposed using some other interface, such as CLI, GUI or an API.

CalcOperation

Bases: str, Enum

Supported operations of calculate.

Source code in src/fair_python_cookiecutter_demo/lib.py
10
11
12
13
14
15
16
17
class CalcOperation(str, Enum):
    """Supported operations of `calculate`."""

    add = "add"
    multiply = "multiply"
    subtract = "subtract"
    divide = "divide"
    power = "power"

calculate

calculate(op: CalcOperation, x: int, y: int)

Calculate result of an operation on two integer numbers.

Source code in src/fair_python_cookiecutter_demo/lib.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def calculate(op: CalcOperation, x: int, y: int):
    """Calculate result of an operation on two integer numbers."""
    if not isinstance(op, CalcOperation):
        raise ValueError(f"Unknown operation: {op}")

    if op == CalcOperation.add:
        return x + y
    elif op == CalcOperation.multiply:
        return x * y
    elif op == CalcOperation.subtract:
        return x - y
    elif op == CalcOperation.divide:
        return x // y

    err = f"Operation {op} is not implemented!"
    raise NotImplementedError(err)