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.

Source Distribution

pituo-0.0.2.tar.gz (1.8 kB view details)

Uploaded Source

File details

Details for the file pituo-0.0.2.tar.gz.

File metadata

  • Download URL: pituo-0.0.2.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.6.4

File hashes

Hashes for pituo-0.0.2.tar.gz
Algorithm Hash digest
SHA256 18fac7d8c69fcf4552a5d0238a9e5f6131bd1858924d0973d54ccbbfd5513d87
MD5 bbe3ad5c11d8b406076dd8e42c7ac68d
BLAKE2b-256 d28ff4ff0a7879e03034d5a215517169b27207237c9da0cf95c1be9c1e47aa6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page