Skip to main content

Go-styled errors in Python.

Project description

pituo

Go-styled errors in Python.

Installation

Using pip: pip install -U pituo

Usage

Import the function pituo from the package:

from pituo import pituo

Using decorator syntax

@pituo
def divide(dividend, divisor):
    """
    Return the result of the division between dividend and divisor.
    May raise a ZeroDivisionError if divisor is 0.
    """
    return dividend / divisor

quotient, err = divide(1, 0)

if err is not None:
    print(err)          # Prints "division by zero"
else:
    print(quotient)

Wrapping the function

def divide(dividend, divisor):
    """
    Return the result of the division between dividend and divisor.
    May raise a ZeroDivisionError if divisor is 0.
    """
    return dividend / divisor

divide = pituo(divide)

quotient, err = divide(4, 1)

if err is not None:
    print(err)
else:
    print(quotient)     # Prints 4

For more examples, see the tests folder.

License

This project is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pituo, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size pituo-0.0.2.tar.gz (1.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page