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
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
799198d0493dff172a6e98f3ff6d90f5f47d79854b1253ee24869893949e8ff3
|
|
| MD5 |
2046474263c382ff3c7644a9a5960622
|
|
| BLAKE2b-256 |
aae997ef2f4f9c93fde10fc547434cd98ac37fd15762ecdada6186e41e7a1424
|
File details
Details for the file safe_returns-0.2.0-py3-none-any.whl.
File metadata
- Download URL: safe_returns-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
838d1f42d31ac214082d8a17c3c70c46427a801261941e18b8eae42078c1c2b9
|
|
| MD5 |
e39a0ecc262db64b7e0f58b3c957a76c
|
|
| BLAKE2b-256 |
d092a3a7d57c800728faad067524c59298d9fa4b6811cdc3246418ec6c9e5cbd
|