Name | error-mapper JSON |
Version |
1.0.6
JSON |
| download |
home_page | None |
Summary | Decorator error mapper |
upload_time | 2024-07-22 17:21:16 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | None |
keywords |
decorator
error mapping
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Error-mapper
[![image](https://img.shields.io/pypi/v/error-mapper.svg)](https://pypi.python.org/pypi/error-mapper)
[![image](https://img.shields.io/pypi/l/error-mapper.svg)](https://github.com/likeinlife/error_mapper/blob/main/LICENSE)
[![codecov](https://codecov.io/gh/likeinlife/error_mapper/graph/badge.svg?token=SP80G3U9RT)](https://codecov.io/gh/likeinlife/error_mapper)
<a href="http://mypy-lang.org/" target="_blank"><img src="https://img.shields.io/badge/mypy-checked-1F5082.svg" alt="Mypy checked"></a>
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://img.shields.io/pypi/pyversions/error-mapper.svg)](https://pypi.python.org/pypi/error-mapper)
Python error mapper based on decorators.
# Installing
`pip install error-mapper`
# Example
## Error map
```python
from error_mapper import ErrorMapType, error_map_decorator
class SuppressedError(Exception): ...
class RaiseError(Exception): ...
error_map: ErrorMapType = {
SuppressedError: RaiseError,
}
@error_map_decorator(error_map, RaiseError)
def fn() -> None:
raise SuppressedError
```
## On error execute
```python
from error_mapper import ErrorMapTypeExecute, on_error_execute
class SuppressedError(Exception): ...
class RaiseError(Exception): ...
def process_error(error: Exception) -> tp.NoReturn:
raise RaiseError from error
error_map: ErrorMapTypeExecute = {
SuppressedError: process_error,
}
@on_error_execute(error_map, RaiseError)
def fn() -> None:
raise SuppressedError
```
## Suppress error to None
```python
from error_mapper import suppress_to_none
class SuppressedError(Exception): ...
class RaiseError(Exception): ...
@suppress_to_none(SuppressedError)
def fn() -> None:
raise SuppressedError
assert fn() is None
```
# Testing, linting, formatting
- `rye test`
- `rye lint`
- `rye fmt`
Raw data
{
"_id": null,
"home_page": null,
"name": "error-mapper",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "decorator, error mapping",
"author": null,
"author_email": "likeinlife <likeinlife@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/c4/5d/8f630dda4644a8bdb973375076007cec44a9be2eefcb042ad2deb280815c/error_mapper-1.0.6.tar.gz",
"platform": null,
"description": "# Error-mapper\n\n[![image](https://img.shields.io/pypi/v/error-mapper.svg)](https://pypi.python.org/pypi/error-mapper)\n[![image](https://img.shields.io/pypi/l/error-mapper.svg)](https://github.com/likeinlife/error_mapper/blob/main/LICENSE)\n[![codecov](https://codecov.io/gh/likeinlife/error_mapper/graph/badge.svg?token=SP80G3U9RT)](https://codecov.io/gh/likeinlife/error_mapper)\n<a href=\"http://mypy-lang.org/\" target=\"_blank\"><img src=\"https://img.shields.io/badge/mypy-checked-1F5082.svg\" alt=\"Mypy checked\"></a>\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![image](https://img.shields.io/pypi/pyversions/error-mapper.svg)](https://pypi.python.org/pypi/error-mapper)\n\nPython error mapper based on decorators.\n\n# Installing\n\n`pip install error-mapper`\n\n# Example\n\n## Error map\n\n```python\nfrom error_mapper import ErrorMapType, error_map_decorator\n\nclass SuppressedError(Exception): ...\n\nclass RaiseError(Exception): ...\n\nerror_map: ErrorMapType = {\n SuppressedError: RaiseError,\n}\n\n@error_map_decorator(error_map, RaiseError)\ndef fn() -> None:\n raise SuppressedError\n```\n\n## On error execute\n\n```python\nfrom error_mapper import ErrorMapTypeExecute, on_error_execute\n\nclass SuppressedError(Exception): ...\n\nclass RaiseError(Exception): ...\n\ndef process_error(error: Exception) -> tp.NoReturn:\n raise RaiseError from error\n\nerror_map: ErrorMapTypeExecute = {\n SuppressedError: process_error,\n}\n\n@on_error_execute(error_map, RaiseError)\ndef fn() -> None:\n raise SuppressedError\n```\n\n## Suppress error to None\n\n```python\nfrom error_mapper import suppress_to_none\n\n\nclass SuppressedError(Exception): ...\n\n\nclass RaiseError(Exception): ...\n\n\n@suppress_to_none(SuppressedError)\ndef fn() -> None:\n raise SuppressedError\n\n\nassert fn() is None\n\n```\n\n# Testing, linting, formatting\n\n- `rye test`\n- `rye lint`\n- `rye fmt`\n",
"bugtrack_url": null,
"license": null,
"summary": "Decorator error mapper",
"version": "1.0.6",
"project_urls": {
"Homepage": "https://pypi.org/project/error-mapper/",
"Repository": "https://github.com/likeinlife/error_mapper"
},
"split_keywords": [
"decorator",
" error mapping"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fe8b456c490dab9578b596cd75a6b39d53b0306da6bf7f5653b8c840572a0aba",
"md5": "7fc89bedd75c995a2530240e79ddc237",
"sha256": "65d764ecdedc3adcbaa8ab718cf148fdcf23b151e2345530f5c8dbf4b477c384"
},
"downloads": -1,
"filename": "error_mapper-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7fc89bedd75c995a2530240e79ddc237",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 9337,
"upload_time": "2024-07-22T17:21:14",
"upload_time_iso_8601": "2024-07-22T17:21:14.725450Z",
"url": "https://files.pythonhosted.org/packages/fe/8b/456c490dab9578b596cd75a6b39d53b0306da6bf7f5653b8c840572a0aba/error_mapper-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c45d8f630dda4644a8bdb973375076007cec44a9be2eefcb042ad2deb280815c",
"md5": "f2d82b18f4a5e8d73dca9bbbb237efb0",
"sha256": "5fb9c1128c54d73a6cf7586271f76bb4d1d7c10314ea4c7d7b2cc6ef793b9288"
},
"downloads": -1,
"filename": "error_mapper-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "f2d82b18f4a5e8d73dca9bbbb237efb0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 7910,
"upload_time": "2024-07-22T17:21:16",
"upload_time_iso_8601": "2024-07-22T17:21:16.275022Z",
"url": "https://files.pythonhosted.org/packages/c4/5d/8f630dda4644a8bdb973375076007cec44a9be2eefcb042ad2deb280815c/error_mapper-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-22 17:21:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "likeinlife",
"github_project": "error_mapper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "error-mapper"
}