{"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,"search_vec":"'-3.12':34 '0.5.0':30 '3.9':33 'activ':17 'assert':3,13,39 'current':27 'debug':40 'drop':7 'drop-in':6 'even':18 'irregular':38 'mode':26 'o':24 'optim':25,41 'provid':4 'python':11,20,32 'releas':37 'remain':16 'replac':9 'run':22 'safe':2 'safe-assert':1 'statement':14 'support':31 'test':42 'version':29","created_at":"2026-05-01T08:13:41.331690+00:00","updated_at":"2026-05-01T08:13:41.331690+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.5.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/sponsors/wemake-services","docs":null,"changelog":null,"pypi":"https://pypi.org/project/safe-assert/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}