Skip to content

Impl ux imrpovment v2#3

Merged
ZuidVolt merged 8 commits into
mainfrom
impl-ux-imrpovment-v2
Mar 12, 2026
Merged

Impl ux imrpovment v2#3
ZuidVolt merged 8 commits into
mainfrom
impl-ux-imrpovment-v2

Conversation

@ZuidVolt

Copy link
Copy Markdown
Owner

No description provided.

This commit introduces `assert_ok`, a new utility for the `result`
library.
`assert_ok` can be used as both a standalone function and a context
manager
to enforce that a `Result` is `Ok`. If an `Err` is encountered, it
raises
an `AssertionError` with a configurable message. The context manager
version
also includes automatic scanning of local variables for `Err`
assignments,
providing fail-fast error detection.

This feature enhances the developer experience by providing a concise
and
explicit way to handle expected successful outcomes and catch unexpected
errors early.
Introduce `catch_boundary` for class-level exception wrapping and
`catch_instance` for wrapping individual object instances. These
utilities simplify the integration of external libraries or classes that
raise exceptions into the Result type system.
Introduces `retry_result` and `retry_result_async` decorators to the
`future` module, allowing for configurable retries of operations that
return a `Result`. These decorators support specifying the number of
attempts, a `retry_if` predicate for selective retries, and a `catch`
parameter to handle exceptions by converting them into `Err` variants.
Additionally, they include support for backoff delays.
The `future.py` module contained adapter utilities like `SafeStream`,
`SafeStreamAsync`, `catch_boundary`, `catch_each_iter`,
`catch_each_iter_async`, and `catch_instance`. These utilities are now
core functionality and have been moved to the `result.adapters`
submodule.

This refactoring:
- Consolidates related functionality into a dedicated module.
- Removes the `future.py` module, which was marked as experimental and
  may have caused confusion.
- Updates imports in `result/__init__.py` to reflect the new module
  structure.
- Updates the documentation `docs/api/adapters.md` to point to the
  correct module.
The 'Future' documentation page has been removed as it is no longer
relevant. The mkdocs.yml configuration has been updated to point to the
'adapters' page instead.
@ZuidVolt ZuidVolt merged commit 8223bd9 into main Mar 12, 2026
1 of 2 checks passed
@ZuidVolt ZuidVolt deleted the impl-ux-imrpovment-v2 branch March 12, 2026 05:11
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience of the 'result' pattern library by introducing a suite of new utilities focused on integration, resilience, and assertion. The 'future' module has been rebranded as 'adapters', now housing stable tools like 'catch_boundary' and 'catch_instance' for seamlessly integrating external APIs. Additionally, new 'retry_result' decorators provide robust mechanisms for handling transient failures, while the 'assert_ok' utility offers convenient ways to enforce 'Ok' invariants in both functional and contextual programming styles. These changes aim to make working with 'Result' types more streamlined and robust.

Highlights

  • Module Restructuring: The 'future' module, previously housing experimental features, has been renamed to 'adapters'. Its utilities are now considered stable 'integration utilities' for the Result Pattern, reflecting a clearer conceptual grouping.
  • New Adapter Utilities: Introduced 'catch_boundary' and 'catch_instance' for bulk lifting and integrating external APIs into the Result Pattern. These allow entire classes or instances to have their public methods automatically return 'Result' types, simplifying error handling at integration points.
  • Result Assertion Utility: Added 'assert_ok', a dual-purpose utility that can assert 'Result' values directly (returning the 'Ok' value or raising an AssertionError) or act as a context manager to automatically detect 'Err' assignments in a local scope, providing fail-fast behavior.
  • Retry Decorators: Implemented 'retry_result' and 'retry_result_async' decorators to add resilience to functions. These automatically re-execute operations that return 'Err' or raise specified exceptions, with configurable attempts, delays, and backoff strategies.
  • Documentation and Test Coverage: Updated documentation to reflect the module rename and new features, and added comprehensive test cases for 'assert_ok', 'catch_boundary', 'catch_instance', and the new retry decorators to ensure correctness and stability.
Changelog
  • docs/api/adapters.md
    • Added new documentation for the 'adapters' module, detailing its purpose and new utilities.
  • docs/api/future.md
    • Removed the deprecated documentation for the 'future' module.
  • mkdocs.yml
    • Updated the navigation configuration to replace the 'Future' entry with 'Adapters', pointing to the new documentation.
  • src/result/init.py
    • Modified imports to expose the new 'SafeStream', 'SafeStreamAsync', 'catch_boundary', 'catch_each_iter', 'catch_each_iter_async', 'catch_instance' from 'adapters'.
    • Exposed 'assert_ok', 'retry_result', and 'retry_result_async' from 'result'.
    • Removed imports from the old 'future' module.
  • src/result/adapters.py
    • Renamed from 'src/result/future.py'.
    • Updated module docstring to reflect its new role as 'Adapters'.
    • Introduced 'catch_boundary' (class decorator) and 'catch_instance' (instance proxy) for bulk exception handling.
    • Removed redundant examples from 'catch_each_iter' and 'SafeStream' methods.
  • src/result/result.py
    • Introduced 'assert_ok' as a function and context manager for asserting 'Ok' results.
    • Added 'retry_result' and 'retry_result_async' decorators for synchronous and asynchronous retry logic.
    • Cleaned up some 'cast' statements to remove 'type: ignore' comments.
  • tests/result/test_assert_ok.py
    • Added new test cases to cover the functional and context manager usage of 'assert_ok', including automatic scanning and nested contexts.
  • tests/result/test_catch_adapters.py
    • Added new test cases for 'catch_boundary' and 'catch_instance', verifying their behavior for synchronous and asynchronous methods, and error mapping.
  • tests/result/test_retry.py
    • Added new test cases for 'retry_result' and 'retry_result_async', covering success, exhaustion, conditional retries, integration with 'catch', and backoff logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request renames the 'future' module to 'adapters', introducing new utilities like catch_boundary (a class decorator) and catch_instance (an instance proxy) for integrating imperative APIs with the Result pattern. It also adds assert_ok for enforcing Ok results and retry_result/retry_result_async decorators for resilience. Documentation and test files are updated accordingly. The review identified an issue in _CatchInstanceProxy where public data attributes were incorrectly masked, returning None instead of their actual value, and a minor bug in ImportError messages where escaped backticks in raw strings led to incorrect formatting.

Comment thread src/result/adapters.py
Comment thread src/result/adapters.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant