Raise exceptions with consistent messages while avoiding the boiler plate.
Compare this:
>>> from exception_template import ExceptionTemplate
>>> class MyException(ExceptionTemplate):
... message = 'Hello, {person}. Here is my {adjective} exception class.'
>>> raise MyException(person='Ryan', adjective='fancy')
Traceback (most recent call last):
...
MyException: Hello, Ryan. Here is my fancy exception class.
To this:
>>> class MyException(Exception):
... def __init__(self, person: str, adjective: str) -> None:
... self.person = person
... self.adjective = adjective
... super().__init__('Hello, {person}. Here is my {adjective} exception class.'
... .format(person=person, adjective=adjective))
>>> raise MyException('Ryan', 'lame')
Traceback (most recent call last):
...
MyException: Hello, Ryan. Here is my lame exception class.
Or this:
>>> class MyException(Exception):
... pass
>>> raise MyException('Hello, Ryan. Here is my exception class with a message I copy-pasted in 500 places.')
Traceback (most recent call last):
...
MyException: Hello, Ryan. Here is my exception class with a message I copy-pasted in 500 places.
Additionally, the ExceptionTemplate parameters are available as members on the exception instance:
>>> try: ... foo() ... except MyException as ex: ... print(ex.person) Ryan
Installing
pip install exception-template
No extra dependencies are needed!
Metadata
Release files for exception-template 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| exception-template-1.0.0.tar.gz | 2.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| exception_template-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.8 kB
Release files / exception-template-1.0.0.tar.gz
| Download URL | exception-template-1.0.0.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a927f01540ae223805d4eb20aad0022185257d773dfbea9989bed457790165ef
|
|
BLAKE2b-256 checksum How to use checksums |
53f9aa7483675cd2cf59fd194a1e76d99423be41e69a4cdbb42a5ef6e4782f9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Release files / exception_template-1.0.0-py3-none-any.whl
| Download URL | exception_template-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
284169005e9c50aff3c3cce5f48e31eda1f545c85042473d12435328b65d811a
|
|
BLAKE2b-256 checksum How to use checksums |
640e162d31a5515b546964c4e30d0efbc54d7ce2857258e81b5dd8a82d0a60f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|