Resulting
Bring the rust Result and Option type into python.
pip install resulting
Result
from resulting import Result, Ok, Err
def get_user_id() -> Result[int, str]:
return Ok(123)
match get_user():
case Ok(user_id):
print(f"User ID: {user_id}")
case Err(msg):
print(f"Failed to get user: {msg}")
Tracebacks
When unwrapping a Result or Option, a traceback will be inserted up to the place the `Err`` was created
This allows you to have the powerful debugging of Exceptions with guarentees of results
# example.py
from resulting import Err
def create_err() -> Err[str]:
return Err("Throw Me!")
res = create_err()
res.unwrap()
Traceback (most recent call last):
File "/example.py", line 7, in <module>
res.unwrap()
File "/example.py", line 6, in <module>
res = create_err()
File "/example.py", line 4, in create_err
return Err("Throw Me!")
RuntimeError: Unwrapped Err(Throw Me!)
Option
from resulting import Option, Some, none
def get_user_id() -> Option[int]:
return Some(123)
match get_user():
case Some(user_id):
print(f"User ID: {user_id}")
case none():
print(f"User does not exist")
Catch Errors
You can use the catch decorator to catch exceptions
from resulting import catch
@catch()
def get_user() -> str:
raise KeyError("User Not Found")
res: Result[str, Exception] = get_user()
or catch specific exceptions using catch
from resulting import catch
@catch([KeyError, LookupError])
def get_user() -> str:
raise KeyError("User Not Found")
res: Result[str, KeyError|LookupError] = get_user()
Optional
You can use the optional wrapper to wrap existing functions in an Option
from resulting import optional
@optional
def get_user() -> str|None:
return "1"
res: Option[str] = get_user()
Metadata
Release files for resulting 1.3.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 | Actions |
|---|---|---|---|---|
| resulting-1.3.0.tar.gz | 6.4 kB | Without provenance | Details for resulting-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| resulting-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for resulting-1.3.0-py3-none-any.whl |
Total release size: 12.5 kB
Release files / resulting-1.3.0.tar.gz
| Download URL | resulting-1.3.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d19bd13234405316d410e1315e520df88f7469aa6dac784cab56718cf07037fa
|
|
BLAKE2b-256 checksum How to use checksums |
0893137db14b89fc4fae506276c313a1b2e45ce0509ee0b28e88fc9e4f764869
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / resulting-1.3.0-py3-none-any.whl
| Download URL | resulting-1.3.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cd67ab69b6cc5bdd3dc49e7a407928b74c197d0ebd09330cf1c5e68ccac81a9
|
|
BLAKE2b-256 checksum How to use checksums |
937e597697bc53c93c097dbe3249399f8e73c1ccc84c2a380a22f92f2b346e08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for resulting 1.3.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.