fix: add explicit return type annotations to BaseVector abstract methods#32516
Conversation
Abstract methods without return type annotations caused pyright to infer `Never` as the return type (since bodies only contain `raise NotImplementedError`). Subclass implementations returning `list[str]` or `None` were then flagged as bad-override errors. Fixes langgenius#32511
Summary of ChangesHello @longway-code, 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 enhances the type safety and clarity of the BaseVector abstract class by introducing explicit return type annotations to its abstract methods. This crucial update addresses a specific problem with the pyright type checker, which previously inferred an incorrect Never return type for these methods, causing bad-override errors when subclasses provided concrete implementations with actual return values. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 correctly adds explicit return type annotations to several abstract methods in the BaseVector class, which resolves typing issues with pyright. The changes are a good improvement for code clarity and type safety. I've added one high-severity comment regarding an inconsistency with add_texts that is surfaced by these changes and could lead to other issues. Additionally, as a suggestion for a follow-up, the get_ids_by_metadata_field method in the same file is not marked as abstract and lacks a return type annotation. Aligning it with the other abstract methods would further improve the consistency and robustness of the BaseVector interface.
Abstract methods without return type annotations caused pyright to infer
Neveras the return type (since bodies only containraise NotImplementedError). Subclass implementations returninglist[str]orNonewere then flagged as bad-override errors.Fixes #32511