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.

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.0.tar.gz (41.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.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for safe_returns-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a0ec0e6824fff214ef4eb9ac51dbb6309cf26f63cf7e3719d5552bcaaf3a686
MD5 1c03f9dfc860af8d13d25f8601d5978a
BLAKE2b-256 31b4ac81bead546ee4b3006354663d1695a5a118975895053128be5a6a6ec4ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for safe_returns-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 350722dd4e38a9de4e20974c6acb06644c4525e6255a28f31b660ca224f04a08
MD5 9478d8a0d0c97105d281b78ae68c85d7
BLAKE2b-256 2bc48378eafa34257cc299a50144bd16af57be1ace3f37f4520ea3bd498fd9fa

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