Skip to main content

Python implementation of the @throws(...) function decorator provided by Kotlin!

Project description

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:

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:

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:

# 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/

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

throws-1.0.6.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

throws-1.0.6-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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