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.1.1.tar.gz
(53.5 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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4824336d36a07d73be3c3f5fa38acc57ca827d0d152ff1b33cf33d3ff4901d9
|
|
| MD5 |
e15b2ab14476890793c29929ec123b44
|
|
| BLAKE2b-256 |
356bf5a8e14bffddc4e420101cdd932023528ded1403f35ae4fbc0db7f8442f5
|
File details
Details for the file safe_returns-0.1.1-py3-none-any.whl.
File metadata
- Download URL: safe_returns-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
099d54d734cae7e2aabc36dfd02644daf40f244ffc91d786cc12cd79a01181c6
|
|
| MD5 |
db7dbf2b6f63d3dad2bb57e3dcdcb202
|
|
| BLAKE2b-256 |
a430ee3bbe577714a07ff869b7647e0d5d28f3f97dacbb4271a2e53ec7b90f9c
|