Skip to content

feat: add type stubs and marker file for PEP 561 support in google.cloud.storage #1528

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

al-chris
Copy link

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

Description

This PR adds a minimal PEP 561-compatible type stub for the google.cloud.storage package to provide better static typing information to editors and type checkers (Pylance / Pyright). The stub exposes the package-level API surface that most callers rely on (Client, Bucket, Blob, Batch, and version) with conservative, correct annotations.

Files changed

  • Added: init.pyi

What this contains

  • Package-level PEP 561 stub with:
    • version: str
    • Batch class (constructor, finish)
    • Blob class (constructor, common properties and a few methods)
    • Bucket class (constructor, blob/get_blob/create/from_string)
    • Client class (constructor, create_anonymous_client, properties, bucket/batch helpers, get_service_account_email)

Motivation

  • Many editor/type-checker complaints originate from dynamic module behavior and lack of top-level type information. Adding a package-level .pyi gives Pylance/Pyright precise signatures for common entry points and reduces false positives for callers importing google.cloud.storage.

Testing / How to validate locally (Windows PowerShell)

  • From repository root:
    • Ensure pyright is installed (npm): npm i -g pyright
    • Run pyright on the workspace: pyright
    • Open the repo in VS Code and ensure Pylance picks up the stub (py.typed file).

Checklist

  • Add package-level .pyi to expose public API
  • (Optional) Add py.typed marker and update packaging

@al-chris al-chris requested review from a team as code owners August 21, 2025 03:17
Copy link

google-cla bot commented Aug 21, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Aug 21, 2025
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Aug 21, 2025
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: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants