This release is a pre-release and may not be stable for production use.
grit
Context manager for shrugging off exceptions less badly.
Subtitle: exception handling for lazy people.
Description and Rationale
Does your code suffer from an overuse of bare exceptions?
What if you could still shrug off exceptions when needed but not be so cringe about it?
try:
foobar()
except Exception:
pass
from grit import Grit
# Full exception stacktrace is automatically logged
with Grit():
foobar()
Quick start
pip install py-grit
>>> from grit import Grit
>>> with Grit():
... raise RunTimeError("something bad")
>>> print("Uh, everything is under control. Situation normal")
Uh, everything is under control. Situation normal
Propagate the errors you care about, while ignoring the ones you don't.
>>> from grit import Grit
>>> with Grit(dnr_list=[ZeroDivisionError]):
... 42 / 0
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
And handle those that require special attention
>>> from grit import Grit
>>> with Grit(handlers={ValueError: print}):
... raise ValueError("what have you done?!")
what have you done?!
Logging and results
Grit() accepts a fallback_handler callable which will be called on the exception if no specific
'handler' (handlers) is found.
By default the fallback_handler will log a full exception traceback at the debug level using self.logger.
To change this behavior, provide your own fallback_handler.
>>> from grit import Grit
>>> with Grit(fallback_handler=print):
... raise TypeError("what have I done?!")
what have I done?!
Usage Examples
TODO ...
Metadata
Release files for py-grit 0.0.1a2
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 |
|---|---|---|---|---|
| py-grit-0.0.1a2.tar.gz | 5.2 kB | Without provenance | Details for py-grit-0.0.1a2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_grit-0.0.1a2-py3-none-any.whl | Python 3 | none | any | Details for py_grit-0.0.1a2-py3-none-any.whl |
Total release size: 9.7 kB
Release files / py-grit-0.0.1a2.tar.gz
| Download URL | py-grit-0.0.1a2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96d46d437f79786a94f240ea1ac7bc5ae0588e6f0c10a42d0947b6f21edabbf5
|
|
BLAKE2b-256 checksum How to use checksums |
3d5adcbb2fc8ff07a4a7d27981e0252c7f073b6fd32304bfa84ab8aa0b4bb866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0
|
Release files / py_grit-0.0.1a2-py3-none-any.whl
| Download URL | py_grit-0.0.1a2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aba1c7d6395a96a2d4c48f2b679af8746cf44bbf37f2bceeffcf061a23b10cb1
|
|
BLAKE2b-256 checksum How to use checksums |
eaa0bbc134fe34a8f94cf7c8e07a99a8c94374f05514a6683f1bcde5b85814f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0
|
Security for py-grit 0.0.1a2
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.