Skip to content

Impl ux imrpovment#2

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

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

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.
@ZuidVolt ZuidVolt marked this pull request as draft March 12, 2026 02:58
@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 introduces a new assert_ok utility designed to enhance the developer experience when working with Result types. It provides a flexible mechanism for asserting that operations must succeed, offering both a functional approach for direct checks and a context manager for fail-fast detection of Err variants within a block of code. This improvement aims to make error handling more explicit and immediate, reducing boilerplate and improving debugging.

Highlights

  • New assert_ok utility: Introduced a new assert_ok utility that functions as both a standalone assertion and a context manager for Result types, providing a more direct way to handle expected Ok outcomes.
  • Fail-fast error detection: The assert_ok context manager uses sys.settrace to automatically detect and raise AssertionError immediately upon assignment of an Err variant to a local variable within its scope.
  • Improved traceback clarity: Added __tracebackhide__ = True to internal helper functions and catch_each_iter wrappers to prevent internal frames from appearing in tracebacks, thereby improving debugging experience.
Changelog
  • src/result/init.py
    • Imported and exposed the new assert_ok utility from the .future module.
  • src/result/future.py
    • Implemented the assert_ok function, supporting both direct Result assertion and context manager usage.
    • Added the AssertOk class, which acts as a context manager to automatically scan for Err assignments using sys.settrace.
    • Introduced _raise_assertion_error to provide cleaner tracebacks for assertion failures.
    • Applied __tracebackhide__ = True to catch_each_iter and catch_each_iter_async wrappers to improve traceback readability.
  • tests/result/test_assert_ok.py
    • Added a new test file to cover the functionality of assert_ok.
    • Included comprehensive tests for functional usage, context manager usage (both explicit and automatic scanning), and nested assert_ok blocks.
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

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.

Comment thread src/result/future.py Outdated
Comment thread src/result/future.py Outdated
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.
@ZuidVolt ZuidVolt force-pushed the impl-ux-imrpovment branch from d79e531 to 80f401e Compare March 12, 2026 03:21
@ZuidVolt ZuidVolt marked this pull request as ready for review March 12, 2026 03:21
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.
@ZuidVolt

Copy link
Copy Markdown
Owner Author

/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.
@ZuidVolt ZuidVolt merged commit 6f80e98 into main Mar 12, 2026
1 check passed
@ZuidVolt ZuidVolt deleted the impl-ux-imrpovment branch March 12, 2026 05:08
@ZuidVolt ZuidVolt restored the impl-ux-imrpovment branch March 12, 2026 05:09
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