Skip to content

Conversation

@googlyrahman
Copy link

Move common client methods to BaseClient

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: storage Issues related to the googleapis/python-storage API. labels Dec 8, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • New Abstract Base Client: A new abstract class, BaseClient, has been introduced in google/cloud/storage/abstracts/base_client.py. This class centralizes common client initialization logic, credential handling, API endpoint determination, and connection management for the python-storage client.
  • Client Class Refactoring: The existing Client class in google/cloud/storage/client.py now inherits from the new BaseClient. Its __init__ method has been significantly simplified by delegating common initialization tasks to the BaseClient's constructor.
  • Code Centralization: Many methods and properties previously defined in Client, such as create_anonymous_client, universe_domain, api_endpoint, update_user_agent, and batch management utilities, have been moved to the BaseClient to promote code reuse and reduce redundancy.
  • Dependency Streamlining: Imports related to credential types, mTLS, local stack management, and various helper functions for endpoint resolution have been removed from client.py as they are now managed within the BaseClient.
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
Contributor

@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 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.

Comment on lines +51 to +55
extra_headers={},
*,
api_key=None,
):
self._base_connection = None
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/python-storage API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant