-
Notifications
You must be signed in to change notification settings - Fork 167
feat(storage): move common client methods to abstract client class #1657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @googlyrahman, 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 foundational architectural improvement by extracting common client functionalities into an abstract base class. This refactoring aims to streamline the client's internal structure, enhance maintainability, and ensure consistent behavior across different client implementations by centralizing core logic related to initialization, authentication, and endpoint configuration. Highlights
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.
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 refactors the google.cloud.storage.client.Client by introducing a new abstract BaseClient class. The BaseClient centralizes common client initialization logic, API endpoint determination (including handling emulator and override environments), credential validation, and connection/batch management. The original Client class now inherits from BaseClient, delegating much of its constructor logic and several properties/methods to the base class, thereby reducing code duplication. A review comment highlights a potential issue with using a mutable default argument for extra_headers in the BaseClient's __init__ method, recommending a change to None and internal initialization to prevent shared state problems.
| extra_headers={}, | ||
| *, | ||
| api_key=None, | ||
| ): | ||
| self._base_connection = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a mutable object like a dictionary as a default argument can lead to unexpected behavior. If a caller modifies the dictionary after initialization, it will affect all subsequent calls that rely on the default. It's safer to use None as the default and initialize an empty dictionary inside the method.
extra_headers=None,
*,
api_key=None,
):
if extra_headers is None:
extra_headers = {}
self._base_connection = None
Move common client methods to BaseClient