Impl ux imrpovment v2#3
Conversation
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.
Summary of ChangesHello, 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
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
No description provided.