Skip to main content

Safe assert for Python that can be used together with optimised mode

Project description

safe-assert

wemake.services Build Status Coverage Python Version wemake-python-styleguide

Allows users to write asserts that are not stripped away in optimized mode.

Features

  • Single simple, pythonic, fast, tested, typed, documented function. That's it!
  • Because safe_assert is a function, it can be easily composed with other functions
  • Fully typed with annotations and checked with mypy, PEP561 compatible

Installation

pip install safe-assert

Examples

The usage is identical to assert keyword, but a function:

from safe_assert import safe_assert

def sort_positive_number(numbers: List[int]) -> List[int]:
    safe_assert(all(num >= 0 for num in numbers), 'found negative')
    return sorted(numbers)

How is it different from regular assert? The major one is that it would not be stripped away with -O flag. So, it still allows to write declarative checks that are safe in production.

The second one is that you can compose it as any other regular function. Useful in conjuction with dry-python projects.

Internals

How does it work internally? It internally raises AssertionError that is also used by the assert keyword itself.

See docs to learn more.

License

MIT.

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

safe-assert-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

safe_assert-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file safe-assert-0.1.0.tar.gz.

File metadata

  • Download URL: safe-assert-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Darwin/18.6.0

File hashes

Hashes for safe-assert-0.1.0.tar.gz
Algorithm Hash digest
SHA256 581ded9f0116d3667bc3486d8010a4f19195ffe62c9e82b710fe037ca54d1f1c
MD5 7e3277264b03d51c314513a8459e77fb
BLAKE2b-256 6d8e53c66a672f809ef96dc6b33397f7293cf6b4929770c0119f7d6640294b45

See more details on using hashes here.

File details

Details for the file safe_assert-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: safe_assert-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Darwin/18.6.0

File hashes

Hashes for safe_assert-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78362c92bf0058f637cf69940ee0b43542413532632573b3a54e47fbac033aa7
MD5 cc39dd69ea750f9b16415d20ea22bd68
BLAKE2b-256 d83a2aa8b49cbcfe58a7baa363447e32f4282e4debd0888c8b67d67fc829fa2a

See more details on using hashes here.

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