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.1.tar.gz (53.5 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.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for safe_returns-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e4824336d36a07d73be3c3f5fa38acc57ca827d0d152ff1b33cf33d3ff4901d9
MD5 e15b2ab14476890793c29929ec123b44
BLAKE2b-256 356bf5a8e14bffddc4e420101cdd932023528ded1403f35ae4fbc0db7f8442f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for safe_returns-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 099d54d734cae7e2aabc36dfd02644daf40f244ffc91d786cc12cd79a01181c6
MD5 db7dbf2b6f63d3dad2bb57e3dcdcb202
BLAKE2b-256 a430ee3bbe577714a07ff869b7647e0d5d28f3f97dacbb4271a2e53ec7b90f9c

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