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.2.tar.gz
(53.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.2.tar.gz.
File metadata
- Download URL: safe_returns-0.1.2.tar.gz
- Upload date:
- Size: 53.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48965e49cc218e701b9c8363aeed4dd52f966697429d3f2a373e475b701e3c09
|
|
| MD5 |
3a32a5470b04ad10448775af93a4edc4
|
|
| BLAKE2b-256 |
068dfc51657a95cfbcbdff5bc432494360318d77b5263ce4dc23967084330c2f
|
File details
Details for the file safe_returns-0.1.2-py3-none-any.whl.
File metadata
- Download URL: safe_returns-0.1.2-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 |
5bf07fadf537431677c604c9874f35d128c88512aa829d22ef3ca573e41d73c0
|
|
| MD5 |
30e597e23fdce31fa8c58bbbbd1246d1
|
|
| BLAKE2b-256 |
a31c3b639613abfdb273b7465cb782f8be3b74d19786719000413e64a4f839f3
|