{"id":3260,"library":"result","title":"Rust-like Result Type for Python","description":"The `result` library provides a Rust-inspired `Result` type for Python 3, enabling explicit error handling without relying solely on exceptions. It introduces `Ok` and `Err` classes to encapsulate success and failure values, respectively, and is fully type-annotated. The current version is 0.17.0, but the library is explicitly marked as 'NOT MAINTAINED' by its authors.","status":"abandoned","version":"0.17.0","language":"en","source_language":"en","source_url":"https://github.com/rustedpy/result","tags":["result type","error handling","functional programming","rust-like","type-safe"],"install":[{"cmd":"pip install result","lang":"bash","label":"Install latest release"}],"dependencies":[],"imports":[{"symbol":"Ok","correct":"from result import Ok"},{"symbol":"Err","correct":"from result import Err"},{"symbol":"Result","correct":"from result import Result"},{"note":"Accessing .ok_value or .err_value directly without first verifying the type (e.g., with `is_ok`, `is_err`, `isinstance`, or pattern matching) will raise an AttributeError if the type does not match.","wrong":"some_result.ok_value","symbol":"is_ok","correct":"from result import is_ok"},{"note":"Accessing .ok_value or .err_value directly without first verifying the type (e.g., with `is_ok`, `is_err`, `isinstance`, or pattern matching) will raise an AttributeError if the type does not match.","wrong":"some_result.err_value","symbol":"is_err","correct":"from result import is_err"}],"quickstart":{"code":"from result import Ok, Err, Result, is_ok\n\ndef divide(a: int, b: int) -> Result[float, str]:\n    if b == 0:\n        return Err(\"Cannot divide by zero\")\n    return Ok(a / b)\n\n# Example usage with isinstance\ndiv_result = divide(10, 2)\nif isinstance(div_result, Ok):\n    print(f\"Division successful: {div_result.ok_value}\")\nelse:\n    print(f\"Division failed: {div_result.err_value}\")\n\ndiv_result_fail = divide(10, 0)\nif is_ok(div_result_fail):\n    print(f\"Division successful: {div_result_fail.ok_value}\")\nelse:\n    print(f\"Division failed: {div_result_fail.err_value}\")\n\n# Example usage with pattern matching (Python 3.10+)\n# This is commented out to ensure compatibility with Python < 3.10 for execution, \n# but is a recommended pattern for newer Python versions.\n# def process_division(a: int, b: int):\n#     match divide(a, b):\n#         case Ok(value):\n#             print(f\"{a} / {b} == {value}\")\n#         case Err(error_message):\n#             print(f\"Error: {error_message}\")\n# process_division(10, 5)\n# process_division(10, 0)","lang":"python","description":"This quickstart demonstrates defining a function that returns a `Result` type, indicating either a successful operation with `Ok(value)` or a failure with `Err(error)`. It shows how to safely unwrap the result using `isinstance` checks or the provided `is_ok`/`is_err` type guards. For Python 3.10 and newer, structural pattern matching (`match` statement) offers a more elegant way to handle `Result` types."},"warnings":[{"fix":"Evaluate migration to a maintained alternative like `dry-python/returns` (specifically its `Result` container) or `overflowy/safe-result` for ongoing support and features.","message":"The `rustedpy/result` library is explicitly marked as 'NOT MAINTAINED' on its GitHub repository. This means there will be no further development, bug fixes, or security updates. Projects relying on this library may face compatibility issues with newer Python versions or unaddressed vulnerabilities.","severity":"breaking","affected_versions":"0.17.0 and potentially older versions"},{"fix":"Always use type checks (e.g., `isinstance(result, Ok)` or `is_ok(result)`) or Python 3.10+ pattern matching to correctly narrow the type before accessing the contained value. Results are immutable; do not attempt to modify their properties directly.","message":"Attempting to access `.ok_value` on an `Err` instance or `.err_value` on an `Ok` instance will result in an `AttributeError`. The `Ok` and `Err` classes are slotted (`__slots__`), preventing arbitrary attribute assignment and making instances immutable.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly add type hints (e.g., `my_var: Result[MySuccessType, MyErrorType] = ...`) and utilize `isinstance` checks to help MyPy correctly narrow types. The library's documentation suggests `isinstance(res, Ok)` as a workaround.","message":"MyPy may sometimes struggle with type inference for `Result` types in certain scenarios, leading to 'Cannot infer type argument' errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}