Prettier error handling for Python
Project description
Tri/bi
This package provides wrappers around functions that nicely handle errors. Reducing code clutter and allowing better responses to uses. This package is inspired by tri-fp
Tri
Tri still lets native exceptions (usually more severe errors) throw, but catches any other errors
>>> from tri import tri, bi
>>> def my_function():
... return 1 / 0 # Zero division error!
>>> # This function raises a "native" exception
>>> tri(my_function)()
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
>>> def my_other_function():
... raise Exception
>>> # This only raises a standard exception, so doesn't fail
>>> tri(my_other_function)()
(Exception(), None)
Bi
Bi, on the contrary, handles all errors blindly. This should only be used if you know what you're doing.
>>> bi(my_function)()
(ZeroDivisionError('division by zero'), None)
Async
Both tri
and bi
support async.
Tri
>>> # Assuming running in async
>>> from tri import atri, abi
>>> async def divide(a, b):
... return a / b
>>> # Let's try to divide by zero
>>> await atri(divide(1, 0))
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
>>> # And with abi?
>>> await abi(divide(1, 0))
(ZeroDivisionError('division by zero'), None)
>>> # If the function takes no params, we can just pass the function name
>>> async def func():
... return "hello"
>>> await atri(func)
(None, "hello")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tribi-1.0.0.tar.gz
(3.4 kB
view details)
Built Distribution
tribi-1.0.0-py3-none-any.whl
(3.9 kB
view details)
File details
Details for the file tribi-1.0.0.tar.gz
.
File metadata
- Download URL: tribi-1.0.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1fb27157842c2099bcf720d2c7732a9e36af6c3fa6f48d5867e7cac8b866923 |
|
MD5 | d15d282075a8d4e46313c773a33b5ea9 |
|
BLAKE2b-256 | 0d0ce45392f895c90dec21f3f0d9cae126dcec9a2daa00a4cd2e00be5d2f8506 |
File details
Details for the file tribi-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: tribi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 282f46cfcdd1bd51ece148ae2505214c9a3e347268d241d9707c12b0ab07cb76 |
|
MD5 | cea2a06e615197d77214b9b307fe4908 |
|
BLAKE2b-256 | 8a2abf703de20cfdc979a11f0e54d7467481ca329590fc4e493e972a919d6379 |