Name | libexcs JSON |
Version |
0.0.2
JSON |
| download |
home_page | |
Summary | An exceptional library |
upload_time | 2023-09-09 14:07:04 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.9 |
license | |
keywords |
exception
exceptions
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
libexcs
=======
*"An exceptional library"*
Installing
~~~~~~~~~~
Just use pip:
::
pip install libexcs
Usage
-----
::
import datetime
from libexcs import root
print("# 1. Subclass, override '_template_' class attribute and define class annotations")
class DerivedException(root.RootException):
_template_ = "Having count={count} for owner={owner}"
count: int
owner: str
extra: datetime.datetime
print("# ----")
ts = datetime.datetime.utcnow()
try:
print("# 2. Raise with kwargs matching the template field names")
raise DerivedException(count=42,
owner="somebody",
extra=dict(timestamp=ts))
except Exception as e:
print("# ----")
print("# 3. Play with raised exceptions")
print(f"# Raised exception 'e': {e}")
print(f">> e.count == {e.count}")
print(f">> e.owner == {e.owner}")
print(f">> e.extra == {e.extra}")
r = repr(e)
print(f">> Exception repr: {r}")
print("# Reconstructing exception from repr...")
e2 = eval(r)
print("# Comparing attribute from original and reconstructed exceptions...")
print(f">> {e2.count} == {e.count} : {e2.count == e.count}")
print("# ----")
print("# 4. See behaviour on incorrect usage")
print("# You will receive TypeError on missing")
try:
raise DerivedException(count=42)
except Exception as e:
print(f">> {e!r}")
Running the tests
-----------------
Simply run tox:
::
tox
Contributing
------------
Contact me through `Issues <https://gitlab.com/pyctrl/libexcs/-/issues>`__.
Versioning
----------
We use `SemVer <http://semver.org/>`__ for versioning. For the versions
available, see the `tags on this
repository <https://gitlab.com/pyctrl/libexcs/-/tags>`__.
Authors
-------
- **Dima Burmistrov** - *Initial work* -
`pyctrl <https://gitlab.com/pyctrl/>`__
*Special thanks to* `Eugene Frolov <https://github.com/phantomii/>`__ *for inspiration.*
License
-------
This project is licensed under the MIT/X11 License - see the
`LICENSE <https://gitlab.com/pyctrl/libexcs/-/blob/main/LICENSE>`__ file for details
Raw data
{
"_id": null,
"home_page": "",
"name": "libexcs",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "exception,exceptions",
"author": "",
"author_email": "Dima Burmistrov <pyctrl.dev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/76/fc/156a803c6233f6d7bd79a4a584efc67d78db8e88c083aaa62e86834fab91/libexcs-0.0.2.tar.gz",
"platform": null,
"description": "libexcs\n=======\n\n*\"An exceptional library\"*\n\n\nInstalling\n~~~~~~~~~~\n\nJust use pip:\n\n::\n\n pip install libexcs\n\n\nUsage\n-----\n\n::\n\n import datetime\n from libexcs import root\n\n print(\"# 1. Subclass, override '_template_' class attribute and define class annotations\")\n\n class DerivedException(root.RootException):\n _template_ = \"Having count={count} for owner={owner}\"\n\n count: int\n owner: str\n extra: datetime.datetime\n\n print(\"# ----\")\n\n ts = datetime.datetime.utcnow()\n try:\n print(\"# 2. Raise with kwargs matching the template field names\")\n raise DerivedException(count=42,\n owner=\"somebody\",\n extra=dict(timestamp=ts))\n except Exception as e:\n print(\"# ----\")\n print(\"# 3. Play with raised exceptions\")\n print(f\"# Raised exception 'e': {e}\")\n\n print(f\">> e.count == {e.count}\")\n print(f\">> e.owner == {e.owner}\")\n print(f\">> e.extra == {e.extra}\")\n\n r = repr(e)\n print(f\">> Exception repr: {r}\")\n print(\"# Reconstructing exception from repr...\")\n e2 = eval(r)\n print(\"# Comparing attribute from original and reconstructed exceptions...\")\n print(f\">> {e2.count} == {e.count} : {e2.count == e.count}\")\n\n print(\"# ----\")\n print(\"# 4. See behaviour on incorrect usage\")\n\n print(\"# You will receive TypeError on missing\")\n try:\n raise DerivedException(count=42)\n except Exception as e:\n print(f\">> {e!r}\")\n\n\nRunning the tests\n-----------------\n\nSimply run tox:\n\n::\n\n tox\n\n\nContributing\n------------\n\nContact me through `Issues <https://gitlab.com/pyctrl/libexcs/-/issues>`__.\n\nVersioning\n----------\n\nWe use `SemVer <http://semver.org/>`__ for versioning. For the versions\navailable, see the `tags on this\nrepository <https://gitlab.com/pyctrl/libexcs/-/tags>`__.\n\nAuthors\n-------\n\n- **Dima Burmistrov** - *Initial work* -\n `pyctrl <https://gitlab.com/pyctrl/>`__\n\n*Special thanks to* `Eugene Frolov <https://github.com/phantomii/>`__ *for inspiration.*\n\nLicense\n-------\n\nThis project is licensed under the MIT/X11 License - see the\n`LICENSE <https://gitlab.com/pyctrl/libexcs/-/blob/main/LICENSE>`__ file for details\n",
"bugtrack_url": null,
"license": "",
"summary": "An exceptional library",
"version": "0.0.2",
"project_urls": {
"Bug Tracker": "https://gitlab.com/pyctrl/libexcs/-/issues",
"Homepage": "https://gitlab.com/pyctrl/libexcs"
},
"split_keywords": [
"exception",
"exceptions"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d49a223180821eb5b6db26675f404ba7a79ea5b106631b5fac2fc006b7f05200",
"md5": "d91bd264cf24303a11ea31fb426d8a66",
"sha256": "2276fed51495aa5a0c57f40a1f51f395c25d55a551b4206d8327d10a26acc7b1"
},
"downloads": -1,
"filename": "libexcs-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d91bd264cf24303a11ea31fb426d8a66",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 3869,
"upload_time": "2023-09-09T14:07:02",
"upload_time_iso_8601": "2023-09-09T14:07:02.376379Z",
"url": "https://files.pythonhosted.org/packages/d4/9a/223180821eb5b6db26675f404ba7a79ea5b106631b5fac2fc006b7f05200/libexcs-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "76fc156a803c6233f6d7bd79a4a584efc67d78db8e88c083aaa62e86834fab91",
"md5": "e78577e2adbe86683e804efea10bc245",
"sha256": "a318f59c7a27355e4a9a4662bc6fa6c14fbe29ea20e493bfd9ac315d8de3a5af"
},
"downloads": -1,
"filename": "libexcs-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "e78577e2adbe86683e804efea10bc245",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 3852,
"upload_time": "2023-09-09T14:07:04",
"upload_time_iso_8601": "2023-09-09T14:07:04.132345Z",
"url": "https://files.pythonhosted.org/packages/76/fc/156a803c6233f6d7bd79a4a584efc67d78db8e88c083aaa62e86834fab91/libexcs-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-09 14:07:04",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "pyctrl",
"gitlab_project": "libexcs",
"lcname": "libexcs"
}