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
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
Metadata
Release files for safe-returns 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| safe_returns-0.2.0.tar.gz | 54.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| safe_returns-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 60.1 kB
Release files / safe_returns-0.2.0.tar.gz
| Download URL | safe_returns-0.2.0.tar.gz |
|---|---|
| Size | 54.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
799198d0493dff172a6e98f3ff6d90f5f47d79854b1253ee24869893949e8ff3
|
|
BLAKE2b-256 checksum How to use checksums |
aae997ef2f4f9c93fde10fc547434cd98ac37fd15762ecdada6186e41e7a1424
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.5
|
Release files / safe_returns-0.2.0-py3-none-any.whl
| Download URL | safe_returns-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
838d1f42d31ac214082d8a17c3c70c46427a801261941e18b8eae42078c1c2b9
|
|
BLAKE2b-256 checksum How to use checksums |
d092a3a7d57c800728faad067524c59298d9fa4b6811cdc3246418ec6c9e5cbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.5
|
Security for safe-returns 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.