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 places 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 the list used by @throw is left blank 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!

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.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

throws-1.0.4-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: throws-1.0.4.tar.gz
  • Upload date:
  • Size: 3.4 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.1

File hashes

Hashes for throws-1.0.4.tar.gz
Algorithm Hash digest
SHA256 46b566aba69526455c79f89ed580f20b09a12c473f7ba332d89583a1418f9db2
MD5 094695566a919e895c786b7bbd578538
BLAKE2b-256 c24c16b49233114bb895815f170f8c0a7b2c1525f8c9893d52effd9c4c8077b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: throws-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 3.8 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.1

File hashes

Hashes for throws-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 47bd93015d3df737057d5af1d6d8f5f3da380473922b3ed7968c73fd096c1221
MD5 e93c4ea73b6269b327b245d3e3a113f2
BLAKE2b-256 ef9eb5c2653e3c8671c6ab1ec35ba82bcda8ff0e2ec4b2398bf8d846c6a41340

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