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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file throws-1.0.6.tar.gz.

File metadata

  • Download URL: throws-1.0.6.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.9

File hashes

Hashes for throws-1.0.6.tar.gz
Algorithm Hash digest
SHA256 8015f70aae2d8434acf245d162a59e2f2f2b523074bc64f6e7b7fb2b196704e4
MD5 db6737c24d2cec81d8744e49c5c17c17
BLAKE2b-256 34e64ceaa2d2df34a3efe681ddf754110e180f219277deeb6ddd51073aee5594

See more details on using hashes here.

File details

Details for the file throws-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: throws-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.9

File hashes

Hashes for throws-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dbbc3150d620e4be37ffa12ef751509d95ba4ad88e54a65cd6c15314e96c061b
MD5 9b6792ec0ea51c8311a55b27df89d1ba
BLAKE2b-256 a5c8cc9772d2975482b58e4fc7406daa24a0beb501a35d284ff5fd2dfd3a8689

See more details on using hashes here.

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