Skip to main content

No project description provided

Project description

plshandle

Create an explicit contract between caller and function that requires the caller to handle specific exceptions raised by the function.

Why

Sometimes, we just have to recover from an error. And because you are a human being, you might not always keep exception handling in mind at all times. This tool helps reduce this mental overhead by reporting all contract violations.

How

A simple example:

from plshandle import plshandle

@plshandle(KeyError)
def get_item(key):
    return {}[key]

get_item(0)  # tool reports this call expression as a contract violation

It is also possible to propagate errors, similar to Java:

@plshandle(KeyError)
def foo():
    return get_item(0)  # o.k., KeyError is propagated, caller's responsibility to handle it

Note: This tool performs static analysis only. As such, dynamic constructs are most likely not supported:

@plshandle(KeyError)
def foo():
    pass
def bar(callback):
    callback()  # nothing reported
bar(foo)

Refer to https://plshandle.readthedocs.io for more in-depth examples.

Before committing

Fetch development dependencies

pip -r requirements-dev.txt

Ensure there are no linting errors

pylint plshandle && mypy -p plshandle

Ensure all tests are successful and code coverage is 100%

pytest && coverage report --fail-under=100

Reformat all files

black plshandle

Or just do this if you have make installed

make check

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

plshandle-0.2.tar.gz (13.3 kB view hashes)

Uploaded Source

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