an alternative to assert - guaranteed to raise
Project description
raise_assert
A short way to check for conditions and raise if it fails, in Python.
Motivation
I get annoyed to need writing all the time variations around:
if not isinstance(my_bool, bool):
raise ValueError("my_bool should be a bool")
And as pointed several places on the net, assert
cannot really be trusted for performing this sort of checks, as asserts can be disabled with the -O
flag, see for example: https://stackoverflow.com/questions/1273211/disable-assertions-in-python .
Solution
The raise_assert package contains a single function that allows writing:
from raise_assert import ras
ras(isinstance(my_bool, bool))
or, if you want an error message (but this is usually not needed, as the stack trace is usually explicit enough):
from raise_assert import ras
ras(isinstance(my_bool, bool), "my_bool must be a bool")
Installation
pip install raise_assert
Why ras?
The word ras
is shortland for both raise_assert and 'rien à signaler', 'nothing to signal' in French.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for raise_assert-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c576724e6ffe7ea85928c1373f965eda696919445cabd5cb82eb66d66221913 |
|
MD5 | 7e59c1bafe01696faf1f0106049efb4a |
|
BLAKE2b-256 | 09c7b5ca852a5957c89d028577d76ce85714da6fd9d843f74d608bd7ec9691c8 |