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")
Real life example
Some examples include...
Safer JSON loading
from tri import bi
safer_loads = bi(json.loads)
error, result = safer_loads(data)
if error:
# Error handling JSON
print("Invalid JSON")
Metadata
Release files for tribi 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tribi-1.0.4.tar.gz | 3.7 kB | Without provenance | Details for tribi-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tribi-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for tribi-1.0.4-py3-none-any.whl |
Total release size: 8.8 kB
Release files / tribi-1.0.4.tar.gz
| Download URL | tribi-1.0.4.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9aa03e960173121ca3f98217be767befbe080465db97bd0d348b7c7e418bb632
|
|
BLAKE2b-256 checksum How to use checksums |
863b0062252c6a74d1dadff56e61536018124e4d5bbe16cb07604c92a4c2975c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
|
Release files / tribi-1.0.4-py3-none-any.whl
| Download URL | tribi-1.0.4-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61dba3216693f9ce4b9bde0b97a0e15ea0452f44069098b5225dc91576a36e26
|
|
BLAKE2b-256 checksum How to use checksums |
6dd081fbe976cc19c0a4c40f703b26928f61d3dd109863814654c221ce9dd4a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
|
Security for tribi 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.