https://pypi.org/project/result/
from result import Ok, Err, Result, is_ok, is_err
def get_user_by_email(email: str) -> Result[User, str]:
"""
Return the user instance or an error message.
"""
if not user_exists(email):
return Err('User does not exist')
if not user_active(email):
return Err('User is inactive')
user = get_user(email)
return Ok(user)
user_result = get_user_by_email(email)
if isinstance(user_result, Ok): # or `is_ok(user_result)`
# type(user_result.ok_value) == User
do_something(user_result.ok_value)
else: # or `elif is_err(user_result)`
# type(user_result.err_value) == str
raise RuntimeError('Could not fetch user: %s' % user_result.err_value)https://toolz.readthedocs.io/en/latest/
https://hypothesis.readthedocs.io/en/latest/
from hypothesis import [given](https://hypothesis.readthedocs.io/en/latest/reference/api.html#hypothesis.given "hypothesis.given"), strategies as st
[@given](https://hypothesis.readthedocs.io/en/latest/reference/api.html#hypothesis.given "hypothesis.given")([st.lists](https://hypothesis.readthedocs.io/en/latest/reference/strategies.html#hypothesis.strategies.lists "hypothesis.strategies.lists")([st.integers](https://hypothesis.readthedocs.io/en/latest/reference/strategies.html#hypothesis.strategies.integers "hypothesis.strategies.integers")() | [st.floats](https://hypothesis.readthedocs.io/en/latest/reference/strategies.html#hypothesis.strategies.floats "hypothesis.strategies.floats")()))
def test_sort_correct(lst):
# lst is a random list of numbers
assert my_sort(lst) == [sorted](https://docs.python.org/3/library/functions.html#sorted "sorted")(lst)
test_sort_correct()https://docs.pydantic.dev/latest/concepts/pydantic_settings/
- A lot more features than older libraries