Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 215
fix: refactor client classes for safer type checking#552
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c67b13
Directly subclass generated PublisherClient
plamut 1daefde
Directly subclass generated SubscriberClient
plamut 1eefc6d
Remove unneded GAPIC helper
plamut 5fe9c35
Remove pytype
plamut 048d109
Re-enable mypy_samples nox session
plamut ace0a03
Convert a comment to docstring in publisher client
plamut 4457779
Add api property back, but deprecated
plamut 1e7bd04
Merge branch 'main' into iss-536-refactor-composition
plamut 8e6b76b
Assure that mypy_samples is not commented out
plamut 67a12c4
Remove redundant type hint casts
plamut 7c210c7
Disable mypy_samples session until blockers resolved
plamut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -29,7 +29,6 @@ pip-log.txt | ||
| .nox | ||
| .cache | ||
| .pytest_cache | ||
| .pytype | ||
| # Mac | ||
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5 google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,11 +18,11 @@ | ||
| import pkg_resources | ||
| import typing | ||
| from typing import cast, Any, Callable, Optional, Sequence, Union | ||
| import warnings | ||
| from google.auth.credentials import AnonymousCredentials # type: ignore | ||
| from google.oauth2 import service_account # type: ignore | ||
| from google.cloud.pubsub_v1 import _gapic | ||
| from google.cloud.pubsub_v1 import types | ||
| from google.cloud.pubsub_v1.subscriber import futures | ||
| from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager | ||
| @@ -42,15 +42,8 @@ | ||
| # a PIP package. | ||
| __version__ = "0.0" | ||
| _DENYLISTED_METHODS = ( | ||
| "publish", | ||
| "from_service_account_file", | ||
| "from_service_account_json", | ||
| ) | ||
| @_gapic.add_methods(subscriber_client.SubscriberClient, denylist=_DENYLISTED_METHODS) | ||
| class Client(object): | ||
| class Client(subscriber_client.SubscriberClient): | ||
| """A subscriber client for Google Cloud Pub/Sub. | ||
| This creates an object that is capable of subscribing to messages. | ||
| @@ -91,12 +84,14 @@ def __init__(self, **kwargs: Any): | ||
| kwargs["credentials"] = AnonymousCredentials() | ||
| # Instantiate the underlying GAPIC client. | ||
| self._api = subscriber_client.SubscriberClient(**kwargs) | ||
| self._target = self._api._transport._host | ||
| super().__init__(**kwargs) | ||
| self._target = self._transport._host | ||
| self._closed = False | ||
| @classmethod | ||
| def from_service_account_file(cls, filename: str, **kwargs: Any) -> "Client": | ||
| def from_service_account_file( # type: ignore[override] | ||
| cls, filename: str, **kwargs: Any | ||
| ) -> "Client": | ||
| """Creates an instance of this client using the provided credentials | ||
| file. | ||
| @@ -112,7 +107,7 @@ def from_service_account_file(cls, filename: str, **kwargs: Any) -> "Client": | ||
| kwargs["credentials"] = credentials | ||
| return cls(**kwargs) | ||
| from_service_account_json = from_service_account_file | ||
| from_service_account_json = from_service_account_file # type: ignore[assignment] | ||
| @property | ||
| def target(self) -> str: | ||
| @@ -123,11 +118,6 @@ def target(self) -> str: | ||
| """ | ||
| return self._target | ||
| @property | ||
| def api(self) -> subscriber_client.SubscriberClient: | ||
| """The underlying gapic API client.""" | ||
| return self._api | ||
plamut marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @property | ||
| def closed(self) -> bool: | ||
| """Return whether the client has been closed and cannot be used anymore. | ||
| @@ -136,6 +126,26 @@ def closed(self) -> bool: | ||
| """ | ||
| return self._closed | ||
| @property | ||
| def api(self): | ||
| """The underlying gapic API client. | ||
| .. versionchanged:: 2.10.0 | ||
| Instead of a GAPIC ``SubscriberClient`` client instance, this property is a | ||
| proxy object to it with the same interface. | ||
| .. deprecated:: 2.10.0 | ||
| Use the GAPIC methods and properties on the client instance directly | ||
| instead of through the :attr:`api` attribute. | ||
| """ | ||
| msg = ( | ||
| 'The "api" property only exists for backward compatibility, access its ' | ||
| 'attributes directly thorugh the client instance (e.g. "client.foo" ' | ||
| 'instead of "client.api.foo").' | ||
| ) | ||
| warnings.warn(msg, category=DeprecationWarning) | ||
| return super() | ||
| def subscribe( | ||
| self, | ||
| subscription: str, | ||
| @@ -266,7 +276,7 @@ def close(self) -> None: | ||
| This method is idempotent. | ||
| """ | ||
| transport = cast("SubscriberGrpcTransport", self.api._transport) | ||
| transport = cast("SubscriberGrpcTransport", self._transport) | ||
| transport.grpc_channel.close() | ||
| self._closed = True | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.