safe-assert


Namesafe-assert JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/wemake-services/safe-assert
SummarySafe assert for Python that can be used together with optimised mode
upload_time2024-03-29 11:45:45
maintainerNone
docs_urlNone
authorsobolevn
requires_python<4.0,>=3.9
licenseMIT
keywords assert utility helper optimized mode
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # safe-assert

[![wemake.services](https://img.shields.io/badge/%20-wemake.services-green.svg?label=%20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake.services)
[![test](https://github.com/wemake-services/safe-assert/workflows/test/badge.svg?branch=master&event=push)](https://github.com/wemake-services/safe-assert/actions?query=workflow%3Atest)
[![codecov](https://codecov.io/gh/wemake-services/safe-assert/branch/master/graph/badge.svg)](https://codecov.io/gh/wemake-services/safe-assert)
[![Python Version](https://img.shields.io/pypi/pyversions/safe-assert.svg)](https://pypi.org/project/safe-assert/)
[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)

Allows users to write composable `assert`s that are not stripped away in [optimized mode](https://docs.python.org/3/using/cmdline.html#cmdoption-o).


## 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](https://www.python.org/dev/peps/pep-0561/)


## Installation

```bash
pip install safe-assert
```


## Examples

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

```python
from safe_assert import safe_assert

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

sort_positive_numbers([1, 2, 3])  # => will work
sort_positive_numbers([-1, 2, 3])
# => will fail in runtime with `AssertionError`
```

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 conjunction with [`dry-python`](https://github.com/dry-python) projects.


## Internals

How does it work internally?
It internally raises [`AssertionError`](https://docs.python.org/3/library/exceptions.html#AssertionError) that is also used by the `assert` keyword itself.

See [docs](https://github.com/wemake-services/safe-assert/blob/master/safe_assert/__init__.py) to learn more.


## License

MIT.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wemake-services/safe-assert",
    "name": "safe-assert",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "assert, utility, helper, optimized mode",
    "author": "sobolevn",
    "author_email": "mail@sobolevn.me",
    "download_url": "https://files.pythonhosted.org/packages/e5/bb/a61f3ff476b4448532978d828a030c8f9bf81b4e04179dadc98df512c0bd/safe_assert-0.5.0.tar.gz",
    "platform": null,
    "description": "# safe-assert\n\n[![wemake.services](https://img.shields.io/badge/%20-wemake.services-green.svg?label=%20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake.services)\n[![test](https://github.com/wemake-services/safe-assert/workflows/test/badge.svg?branch=master&event=push)](https://github.com/wemake-services/safe-assert/actions?query=workflow%3Atest)\n[![codecov](https://codecov.io/gh/wemake-services/safe-assert/branch/master/graph/badge.svg)](https://codecov.io/gh/wemake-services/safe-assert)\n[![Python Version](https://img.shields.io/pypi/pyversions/safe-assert.svg)](https://pypi.org/project/safe-assert/)\n[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)\n\nAllows users to write composable `assert`s that are not stripped away in [optimized mode](https://docs.python.org/3/using/cmdline.html#cmdoption-o).\n\n\n## Features\n\n- Single simple, pythonic, fast, tested, typed, documented function. That's it!\n- Because `safe_assert` is a function, it can be easily composed with other functions\n- Fully typed with annotations and checked with mypy, [PEP561 compatible](https://www.python.org/dev/peps/pep-0561/)\n\n\n## Installation\n\n```bash\npip install safe-assert\n```\n\n\n## Examples\n\nThe usage is identical to `assert` keyword, but a function:\n\n```python\nfrom safe_assert import safe_assert\n\ndef sort_positive_numbers(numbers: List[int]) -> List[int]:\n    safe_assert(all(num >= 0 for num in numbers), 'found negative')\n    return sorted(numbers)\n\nsort_positive_numbers([1, 2, 3])  # => will work\nsort_positive_numbers([-1, 2, 3])\n# => will fail in runtime with `AssertionError`\n```\n\nHow is it different from regular `assert`?\nThe major one is that it would not be stripped away with `-O` flag.\nSo, it still allows to write declarative checks that are safe in production.\n\nThe second one is that you can compose it as any other regular function.\nUseful in conjunction with [`dry-python`](https://github.com/dry-python) projects.\n\n\n## Internals\n\nHow does it work internally?\nIt internally raises [`AssertionError`](https://docs.python.org/3/library/exceptions.html#AssertionError) that is also used by the `assert` keyword itself.\n\nSee [docs](https://github.com/wemake-services/safe-assert/blob/master/safe_assert/__init__.py) to learn more.\n\n\n## License\n\nMIT.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Safe assert for Python that can be used together with optimised mode",
    "version": "0.5.0",
    "project_urls": {
        "Funding": "https://github.com/sponsors/wemake-services",
        "Homepage": "https://github.com/wemake-services/safe-assert",
        "Repository": "https://github.com/wemake-services/safe-assert"
    },
    "split_keywords": [
        "assert",
        " utility",
        " helper",
        " optimized mode"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f0c5096a78bca1285c92384adf4d6517cfbcc1e52ce156583b962ca7fa93f2ab",
                "md5": "f51e3ab835e371a09081a5604858f5b3",
                "sha256": "aec1348bf6baac240d263b1c69eb0c00c0d9dc90c9d73c76cb9ad30d98ea8fd1"
            },
            "downloads": -1,
            "filename": "safe_assert-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f51e3ab835e371a09081a5604858f5b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 4242,
            "upload_time": "2024-03-29T11:45:44",
            "upload_time_iso_8601": "2024-03-29T11:45:44.758044Z",
            "url": "https://files.pythonhosted.org/packages/f0/c5/096a78bca1285c92384adf4d6517cfbcc1e52ce156583b962ca7fa93f2ab/safe_assert-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5bba61f3ff476b4448532978d828a030c8f9bf81b4e04179dadc98df512c0bd",
                "md5": "00188479b8bb764588ad99d033fc6b00",
                "sha256": "3d04d92d28ec6885246c8ed068dfca4109e4dbfb7c12bc1d3f9d825a86907cc9"
            },
            "downloads": -1,
            "filename": "safe_assert-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "00188479b8bb764588ad99d033fc6b00",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 3757,
            "upload_time": "2024-03-29T11:45:45",
            "upload_time_iso_8601": "2024-03-29T11:45:45.865749Z",
            "url": "https://files.pythonhosted.org/packages/e5/bb/a61f3ff476b4448532978d828a030c8f9bf81b4e04179dadc98df512c0bd/safe_assert-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 11:45:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wemake-services",
    "github_project": "safe-assert",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "safe-assert"
}
        
Elapsed time: 0.22901s