Skip to main content

Safe returns function decorator

Project description

safe-returns

A decorator for converting the output type of a function into an algebraic data type, representing the function’s result and its possible exception types. This helps in tracking exception types and improves type-checker hints.

PyPI - Python Version PyPI - Status PyPI - Implementation PyPI - Downloads

Pre-commit uv Ruff Checked with pyright Semantic Versions

Test results Coverage Status

Documentation GitHub License GitHub Release GitHub Repo stars

Install

pypi

pip install safe-returns

Uses

from safe import safe, Success, Failure

@safe @ ValueError | KeyError
def foo() -> int | str: ...


match foo():
    case Success(value=int() as number):
        print(f"It's int {number=}")
    case Success(value=str() as string):
        print(f"It's str {string=}")
    case Failure(error=ValueError()):
        print("Catch ValueError")
    # reportMatchNotExhaustive warning – KeyError are not handled

Documentation

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

safe_returns-0.1.2.tar.gz (53.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safe_returns-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file safe_returns-0.1.2.tar.gz.

File metadata

  • Download URL: safe_returns-0.1.2.tar.gz
  • Upload date:
  • Size: 53.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for safe_returns-0.1.2.tar.gz
Algorithm Hash digest
SHA256 48965e49cc218e701b9c8363aeed4dd52f966697429d3f2a373e475b701e3c09
MD5 3a32a5470b04ad10448775af93a4edc4
BLAKE2b-256 068dfc51657a95cfbcbdff5bc432494360318d77b5263ce4dc23967084330c2f

See more details on using hashes here.

File details

Details for the file safe_returns-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for safe_returns-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5bf07fadf537431677c604c9874f35d128c88512aa829d22ef3ca573e41d73c0
MD5 30e597e23fdce31fa8c58bbbbd1246d1
BLAKE2b-256 a31c3b639613abfdb273b7465cb782f8be3b74d19786719000413e64a4f839f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page