{"id":24552,"library":"safe-assert","title":"safe-assert","description":"Provides a drop-in replacement for Python's assert statement that remains active even when Python is run with -O (optimized mode). Currently at version 0.5.0, supports Python 3.9-3.12, and is released irregularly.","status":"active","version":"0.5.0","language":"python","source_language":"en","source_url":"https://github.com/wemake-services/safe-assert","tags":["assert","debugging","optimization","testing"],"install":[{"cmd":"pip install safe-assert","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"safe_assert is a function, not a module; importing the module directly gives AttributeError when calling safe_assert()","wrong":"import safe_assert","symbol":"safe_assert","correct":"from safe_assert import safe_assert"},{"note":"Custom AssertionError is raised (subclass of builtins.AssertionError)","wrong":null,"symbol":"AssertionError","correct":"from safe_assert import AssertionError"}],"quickstart":{"code":"from safe_assert import safe_assert\n\nx = 0\nsafe_assert(x != 0, \"x should not be zero\")  # raises safe_assert.AssertionError if False, even with python -O","lang":"python","description":"Run this script normally or with python -O; safe_assert will still raise an error."},"warnings":[{"fix":"Use function call syntax: safe_assert(condition, message)","message":"safe_assert is a function, not a replacement for the assert statement syntax. You cannot write `safe_assert x == 1`; you must call it as `safe_assert(x == 1)`.","severity":"gotcha","affected_versions":"all"},{"fix":"If you rely on the return type being NoReturn, update your type hints to None.","message":"Version 0.5.0 changes the return annotation from NoReturn to None. This is a typing-only change; runtime behavior is unaffected.","severity":"deprecated","affected_versions":"0.5.0"},{"fix":"Upgrade to Python 3.9+ or pin safe-assert to <0.5.0.","message":"Python 3.7 and 3.8 support dropped in version 0.5.0.","severity":"breaking","affected_versions":">=0.5.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from safe_assert import safe_assert' instead of 'import safe_assert'.","cause":"Importing the module directly, then trying to call safe_assert.safe_assert() but the function is not exported at module level as an attribute.","error":"AttributeError: module 'safe_assert' has no attribute 'safe_assert'"},{"fix":"Use 'from safe_assert import safe_assert' and then call 'safe_assert(condition, message)'.","cause":"Using 'import safe_assert' and then 'safe_assert(condition, message)' attempts to call the module itself, which is not callable.","error":"TypeError: 'module' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}