Skip to main content

an alternative to assert - guaranteed to raise

Project description


A short way to check for conditions and raise if it fails, in Python.


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: .


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")


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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raise_assert-0.2.tar.gz (2.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page