Skip to content

fix(pubsub): preserve publisher method type annotations - #18106

Draft
ishaangandhi wants to merge 1 commit into
googleapis:mainfrom
ishaangandhi:ishaan/fix-pubsub-annotations
Draft

fix(pubsub): preserve publisher method type annotations#18106
ishaangandhi wants to merge 1 commit into
googleapis:mainfrom
ishaangandhi:ishaan/fix-pubsub-annotations

Conversation

@ishaangandhi

@ishaangandhi ishaangandhi commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Overview

  • Preserve concrete request, retry, and timeout annotations for Pub/Sub publishers.

@google-cla

google-cla Bot commented Aug 13, 2026

Copy link
Copy Markdown

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.

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

Copy link
Copy Markdown
Contributor

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 simplifies retry and timeout type definitions in the Google Cloud Pub/Sub library, including direct imports of timeout classes and updating type annotations for publisher requests. The feedback suggests using Dict instead of dict for backward compatibility and consistency, and simplifying the TimeoutType definition by removing the redundant int type hint since float already encompasses it.

Comment thread packages/google-cloud-pubsub/google/pubsub_v1/services/publisher/async_client.py Outdated
Comment thread packages/google-cloud-pubsub/google/pubsub_v1/types/__init__.py
@ishaangandhi
ishaangandhi marked this pull request as ready for review August 13, 2026 18:49
@ishaangandhi
ishaangandhi requested a review from a team as a code owner August 13, 2026 18:49
@ishaangandhi
ishaangandhi force-pushed the ishaan/fix-pubsub-annotations branch from 56a192f to d8c4582 Compare August 13, 2026 18:49
@ishaangandhi ishaangandhi changed the title [Pub/Sub] Preserve publisher method type annotations fix(pubsub): preserve publisher method type annotations Aug 13, 2026
OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for looking into cleaning up these type annotations!

You're right that with "google-api-core[grpc] >= 2.25.0, <3.0.0", gapic_v1.method._MethodDefault is guaranteed to exist at runtime, making the try/except AttributeError fallback obsolete here.

However, because the files under google/pubsub_v1/ are automatically generated, manual edits will be overwritten during the next generator run and will introduce drift from the other generated client services (like subscriber/client.py).

Would you be open to proposing this change upstream in the generator templates instead ?

You can update the Jinja template directly here:

try:
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object, None] # type: ignore

The PR should only include changes to packages/gapic-generator because the generator fix must first be merged and released to PyPI before downstream packages like google-cloud-pubsub can be regenerated with the updated version.

@parthea
parthea marked this pull request as draft August 18, 2026 15:15
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.

2 participants