Skip to content

Comments

fix: replace KeyError with warning for duplicate registration#7

Merged
Tohrusky merged 1 commit intoEutropicAI:mainfrom
TohruskyDev:main
Sep 26, 2025
Merged

fix: replace KeyError with warning for duplicate registration#7
Tohrusky merged 1 commit intoEutropicAI:mainfrom
TohruskyDev:main

Conversation

@Tohrusky
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Tohrusky, 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 refines the object registration process within the cccv/util/registry.py file. The primary goal is to enhance robustness by changing how duplicate registration attempts are handled. Instead of abruptly terminating execution with a KeyError, the system now gracefully issues a UserWarning, informing developers of the duplicate without interrupting the program flow and ensuring that existing registrations are preserved.

Highlights

  • Error Handling: Replaced a KeyError with a UserWarning when attempting to register an object with a name that already exists in the registry. This prevents the program from crashing and instead issues a non-blocking notification.
  • Module Import: The warnings module was imported to facilitate the new warning mechanism.
  • Code Cleanup: Removed outdated Pyre-related comments (pyre-strict, pyre-ignore-all-errors) from the file.
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.

Copy link

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

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 changes the behavior for duplicate object registration from raising a KeyError to issuing a UserWarning. This makes the registration process more lenient and less strict. The implementation is mostly correct, but I've suggested an improvement to the warning's stacklevel to make it more useful for developers by pointing to their code that caused the duplicate registration, rather than internal library code.

Comment on lines +42 to +46
warnings.warn(
f"[CCCV] An object named '{name}' was already registered in '{self._name}' registry! We will NOT overwrite the existing one.",
UserWarning,
stacklevel=2,
)

Choose a reason for hiding this comment

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

medium

The current stacklevel=2 will cause the warning to point to the register method within this file, which is not very helpful for the end-user. To make the warning more useful, it should point to the line in the user's code where the duplicate registration is attempted. Changing stacklevel to 3 will achieve this by moving up the call stack to the user's code, making it much easier to locate the source of the duplicate registration.

Suggested change
warnings.warn(
f"[CCCV] An object named '{name}' was already registered in '{self._name}' registry! We will NOT overwrite the existing one.",
UserWarning,
stacklevel=2,
)
warnings.warn(
f"[CCCV] An object named '{name}' was already registered in '{self._name}' registry! We will NOT overwrite the existing one.",
UserWarning,
stacklevel=3,
)

@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.62%. Comparing base (80fefa4) to head (01c8f60).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cccv/util/registry.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main       #7   +/-   ##
=======================================
  Coverage   92.61%   92.62%           
=======================================
  Files          40       40           
  Lines        1219     1220    +1     
=======================================
+ Hits         1129     1130    +1     
  Misses         90       90           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tohrusky Tohrusky merged commit 6e85a15 into EutropicAI:main Sep 26, 2025
10 of 11 checks passed
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