Skip to main content

Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.

Project description

optres

Yet another Rust's Option<T> and Result<T, E> simple implementation in Python.

Python package PyPI version License: MIT pre-commit Github pages

Installation

python3 -m pip install -U optres

Example

from optres import unwrap, Result, Err, is_ok, is_err, unwrap_err
from typing import LiteralString


def return_result(x: int | None) -> Result[int, LiteralString]:
    return Err("not int") if x is None else x


def example() -> None:
    a: int | None = 1
    c: int = unwrap(a)
    print(c)
    assert is_ok(return_result(a))
    a = None
    # unwrap(a) # error := panic in Rust.
    may_be_err = return_result(a)
    assert is_err(may_be_err)
    print(unwrap_err(may_be_err))


if __name__ == "__main__":
    example()

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

optres-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

optres-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file optres-0.1.0.tar.gz.

File metadata

  • Download URL: optres-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-58-generic

File hashes

Hashes for optres-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4266feb7dec9e35c344a284d6b9b53ab353e2424f93a302b7ef2217de7602005
MD5 ca8ec3f28ce7b85e6d3d365125d78718
BLAKE2b-256 c9e8225ecf246eedcfd1a149fbbf87d40b2a826a79c649abec52015ab11629ff

See more details on using hashes here.

File details

Details for the file optres-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: optres-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-58-generic

File hashes

Hashes for optres-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc3e125ccc4693ed3f0a9a5e3004f309c8e8b7926fc736189732209ccd61ac6a
MD5 74b319ab08bcde68e5c8f55899a064b6
BLAKE2b-256 9ce1da55dc35ea20d0d295ada7512e3cba4656798d23a8182ffa029223a1dd3b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page