Impl ux imrpovment#2
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.
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 introduces a new 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
This pull request introduces a new assert_ok utility, which provides both a direct function and a context manager to assert that Result instances are Ok. The context manager's use of sys.settrace for automatic error detection is a powerful addition for debugging and testing, and its performance implications are well-documented. The changes include the core implementation, its public export, and a comprehensive new test suite. My feedback focuses on refining the type hints for greater precision and simplifying a section of the code by removing a potentially unnecessary type suppression.
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.
d79e531 to
80f401e
Compare
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.
|
/gemini review |
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.
No description provided.