mentortools/libs/: exception-tools-abm-1.0.79346 metadata and description
Tools and components to work with exceptions
| author | mike |
| author_email | m.orlov@technokert.ru |
| classifiers |
|
| description_content_type | text/markdown |
| license | Proprietary. All rights reserved. Confidential and belonging to ABM. |
| requires_dist |
|
| requires_python | >=3.11,<4.0 |
| File | Tox results | History |
|---|---|---|
exception_tools_abm-1.0.79346-py3-none-any.whl
|
|
|
exception_tools_abm-1.0.79346.tar.gz
|
|
from typing import Any
Exception tools
Tools and components to work with exceptions
Examples:
from typing import Any
from exception_tools import raise_if, raise_if_not, repr_exception
def do_the_thing(val: int | Any) -> None:
raise_if_not(isinstance(val, int), TypeError(f'Required type int, got {type(val).__qualname__}'))
raise_if(val <= 0, ValueError, 'Only positive values allowed, got', val)
# actual work
try:
do_the_thing(None)
except TypeError as e:
assert repr_exception(e) == "TypeError: Required type int, got NoneType"
try:
do_the_thing(0)
except ValueError as e:
assert repr_exception(e) == "ValueError: ('Only positive values allowed, got', 0)"