https://github.com/thahnen/throws
Python library to emulate the @throws decorator of Kotlin, mainly for documentation and debugging.
https://github.com/thahnen/throws
Last synced: over 1 year ago
JSON representation
Python library to emulate the @throws decorator of Kotlin, mainly for documentation and debugging.
- Host: GitHub
- URL: https://github.com/thahnen/throws
- Owner: thahnen
- License: mit
- Created: 2021-04-13T09:58:22.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-31T20:53:28.000Z (over 4 years ago)
- Last Synced: 2025-02-22T10:17:37.943Z (over 1 year ago)
- Language: Python
- Homepage: https://pypi.org/project/throws/
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python: throws
Small but simple library providing a function decorator similar to Kotlins *@throws(...)*
decorator with the small difference that multiple exceptions or errors can be combined in just one
single annotation. Should maily used for documentation and debugging purposes.
## Installation
Installation is possible using the Python *pip* command line tool. For you the command to install
this library may look like this:
```bash
pip3 install throws
```
## Usage
To use the *@throw* decorator simply place it before the function declaration providing every
possible exception raised by the function. For a quick example see below:
```python
from throws import throws
@throws(IOError, ValueError)
def check_version(version_file: str) -> bool:
with open(version_file, "r", encoding = "utf-8") as vf:
if (float(vf.read() > 1.0):
return true
return false
```
The library provides two Exceptions by itself, the *EmptyListException* and the
*InvalidRaisedException*. The first one is raised when there are no parameters provided to
*@throw* and the function decorated is run. The second one occours when the function raises an
exception which is not provided to the decorator, providing the developer with feedback that he
might have forgotten about handling this specific exception!
## Uploading a new version
To create and upload a new version to PyPI use the following commands:
```bash
# 1) Check for correctness
python3 setup.py check
# 2) Create distributable files
python3 setup.py sdist bdist_wheel
# 3) Check distributable files
python3 -m twine check dist/*
# 4) Upload distributable files
python3 -m twine upload dist/*
```
## Links
Library at the Python Package Index (PyPI): https://pypi.org/project/throws/