Skip to content

Commit 13587b3

Browse files
committed
Add type annotations for google.
1 parent a0417a9 commit 13587b3

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

google/testcontainers/google/pubsub.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
13-
13+
from google.cloud import pubsub
14+
import grpc
15+
from typing import Optional
1416
from testcontainers.core.container import DockerContainer
1517

1618

@@ -34,9 +36,8 @@ def test_docker_run_pubsub():
3436
topic_path = publisher.topic_path(pubsub.project, "my-topic")
3537
topic = publisher.create_topic(topic_path)
3638
"""
37-
38-
def __init__(self, image="google/cloud-sdk:emulators",
39-
project="test-project", port=8432, **kwargs):
39+
def __init__(self, image: str = "google/cloud-sdk:emulators", project: str = "test-project",
40+
port: int = 8432, **kwargs) -> None:
4041
super(PubSubContainer, self).__init__(image=image, **kwargs)
4142
self.project = project
4243
self.port = port
@@ -46,21 +47,19 @@ def __init__(self, image="google/cloud-sdk:emulators",
4647
project=self.project, port=self.port,
4748
))
4849

49-
def get_pubsub_emulator_host(self):
50+
def get_pubsub_emulator_host(self) -> str:
5051
return "{host}:{port}".format(host=self.get_container_host_ip(),
5152
port=self.get_exposed_port(self.port))
5253

53-
def _get_channel(self, channel=None):
54+
def _get_channel(self, channel: Optional[grpc.Channel] = None) -> grpc.Channel:
5455
if channel is None:
55-
import grpc
5656
return grpc.insecure_channel(target=self.get_pubsub_emulator_host())
57+
return channel
5758

58-
def get_publisher_client(self, **kwargs):
59-
from google.cloud import pubsub
59+
def get_publisher_client(self, **kwargs) -> pubsub.PublisherClient:
6060
kwargs['channel'] = self._get_channel(kwargs.get('channel'))
6161
return pubsub.PublisherClient(**kwargs)
6262

63-
def get_subscriber_client(self, **kwargs):
64-
from google.cloud import pubsub
63+
def get_subscriber_client(self, **kwargs) -> pubsub.SubscriberClient:
6564
kwargs['channel'] = self._get_channel(kwargs.get('channel'))
6665
return pubsub.SubscriberClient(**kwargs)

0 commit comments

Comments
 (0)