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.2.0.tar.gz (54.0 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.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for safe_returns-0.2.0.tar.gz
Algorithm Hash digest
SHA256 799198d0493dff172a6e98f3ff6d90f5f47d79854b1253ee24869893949e8ff3
MD5 2046474263c382ff3c7644a9a5960622
BLAKE2b-256 aae997ef2f4f9c93fde10fc547434cd98ac37fd15762ecdada6186e41e7a1424

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for safe_returns-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 838d1f42d31ac214082d8a17c3c70c46427a801261941e18b8eae42078c1c2b9
MD5 e39a0ecc262db64b7e0f58b3c957a76c
BLAKE2b-256 d092a3a7d57c800728faad067524c59298d9fa4b6811cdc3246418ec6c9e5cbd

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