Skip to main content

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


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

Uploaded Source

File details

Details for the file raise_assert-0.2.tar.gz.

File metadata

  • Download URL: raise_assert-0.2.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for raise_assert-0.2.tar.gz
Algorithm Hash digest
SHA256 bed12dc0746b230f2883840867b84ea4ab147e6866499e982657b7ca7eacac1e
MD5 809bd64c1e0208176a179cfed709c5d3
BLAKE2b-256 eabdd2a478fe816f3d2f0a511958d0cb8560e753dd6f794e44f0487482988536

See more details on using hashes here.

Supported by

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