Skip to content

Releases: Dev2Forge/BasicReturns

v0.1.2

14 Dec 00:50

Choose a tag to compare

Unify all the return values of every function in your project with these basic models. If you are accustomed to working with APIs, it will be identical to these models.

Example of use:

1. Install the micromodule

pip install BasicReturns

2. Use it

from BasicReturns import BasicReturn, DataAndMsgReturn

def divide_numbers(a: float, b: float) -> DataAndMsgReturn:
    """Safely divide two numbers with unified return structure."""
    response = DataAndMsgReturn()

    try:
        if b == 0:
            raise ZeroDivisionError("Cannot divide by zero")
        response.data = a / b
        response.msg = "Division completed successfully"
    except Exception as e:
        response.ok = False
        response.error = e
        response.msg = "Division failed"

    return response

# Usage example
result = divide_numbers(10, 2)

if result.ok:
    print(f"{result.msg}: {result.data}")  # Division completed successfully: 5.0
else:
    print(f"{result.msg}: {result.error}")  # Division failed: Cannot divide by zero

Full Changelog: v0.1.1...v0.1.2