Context Managers for Controlling Exception Chaining
Provides a different way of controlling exception chaining (the implicit __context__ and explicit __cause__) beyond just raise ... from ....
Versioning
This library’s version numbers follow the SemVer 2.0.0 specification.
Installation
pip install exceptioncontext
Usage
Import as needed:
from exceptioncontext import cause, context, suppress_context
Explicitly chain exception (set __cause__):
with cause(Exception("foo")):
raise Exception("bar")
Override implicitly chained exception (set __context__):
with context(Exception("foo")):
raise Exception("bar")
Manually control context suppression (set __suppress_context__):
with suppress_context(False):
raise Exception("foo")
exceptioncontext makes exception chaining fully independent of the raise statement, and freely composable with other code:
with cause(earlier_exception):
helper_function()
Portability
Portable to all releases of both Python 3 and Python 2.
(The oldest tested is 2.5, but it will likely work as far back as 2.2 when paired with something like with-as-a-function.)
On implementations of Python where setting the exception chaining attributes on an exception raises an AttributeError, exceptioncontext gracefully degrades to doing nothing.
Metadata
Release files for exceptioncontext 1.0.9
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 | |
|---|---|---|---|---|
| exceptioncontext-1.0.9.tar.gz | 3.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| exceptioncontext-1.0.9-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 6.5 kB
Release files / exceptioncontext-1.0.9.tar.gz
| Download URL | exceptioncontext-1.0.9.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc972f8a397b0b5e6dca59ea6f2af50c5f1eff909ceea82e5b0ba5e5f4c5adc8
|
|
BLAKE2b-256 checksum How to use checksums |
4be34641c826eeb1da0b12532a0f46ca6d1bf2558cf49f3dd2af87eb73e650cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Release files / exceptioncontext-1.0.9-py2.py3-none-any.whl
| Download URL | exceptioncontext-1.0.9-py2.py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6de7d20a3fa9e7dc67551d8bc084b5dab62bf5cc470630fedf7029b9a8b03333
|
|
BLAKE2b-256 checksum How to use checksums |
e816617f3e7c9dab0db377ad3e90fbe06c4e2edaa7de0493f901c614240fc186
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Security for exceptioncontext 1.0.9
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.