ctxtools
- Contextlib fun
Utilities for with-statement contexts
- class torxtools.ctxtools.reraise_from_none(*exceptions)
Similar to contextlib.suppress, but with decorator support, and that re-raises exception from None instead of hiding it.
Example
@contextlib.reraise_from_none(ValueError) def foobar(): ...
- class torxtools.ctxtools.suppress(*exceptions)
A version of contextlib.suppress with decorator support.
Example
@contextlib.suppress(ValueError) def foobar(): ...
- class torxtools.ctxtools.suppress_traceback(keyboard_exitcode=1, system_exitcode=1, error_exitcode=1)
Context handler to suppress tracebacks and pretty print an error.
In case exception is KeyboardInterrupt, then the error is suppressed. No assumption, error or normal exit, is made for why Ctrl-C was used.
Example
if __name__ == "__main__": with suppress_traceback(): main()