Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

raise-assert

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raise-assert

an alternative to assert - guaranteed to raise

  • 0.2
  • PyPI
  • Socket score

Maintainers
1

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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc