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.0.tar.gz
(41.8 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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a0ec0e6824fff214ef4eb9ac51dbb6309cf26f63cf7e3719d5552bcaaf3a686
|
|
| MD5 |
1c03f9dfc860af8d13d25f8601d5978a
|
|
| BLAKE2b-256 |
31b4ac81bead546ee4b3006354663d1695a5a118975895053128be5a6a6ec4ee
|
File details
Details for the file safe_returns-0.1.0-py3-none-any.whl.
File metadata
- Download URL: safe_returns-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
350722dd4e38a9de4e20974c6acb06644c4525e6255a28f31b660ca224f04a08
|
|
| MD5 |
9478d8a0d0c97105d281b78ae68c85d7
|
|
| BLAKE2b-256 |
2bc48378eafa34257cc299a50144bd16af57be1ace3f37f4520ea3bd498fd9fa
|