From 629365f32d67bf3a6863615832e5443e185b8e3b Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 7 Oct 2021 00:40:45 +0000 Subject: [PATCH] feat: add context manager support in client (#247) - [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: https://github.com/googleapis/googleapis/commit/787f8c9a731f44e74a90b9847d48659ca9462d10 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9 --- .../services/image_annotator/async_client.py | 6 +++ .../services/image_annotator/client.py | 18 +++++-- .../image_annotator/transports/base.py | 9 ++++ .../image_annotator/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../services/product_search/async_client.py | 6 +++ .../services/product_search/client.py | 18 +++++-- .../product_search/transports/base.py | 9 ++++ .../product_search/transports/grpc.py | 3 ++ .../product_search/transports/grpc_asyncio.py | 3 ++ google/cloud/vision_v1/types/geometry.py | 1 + .../cloud/vision_v1/types/image_annotator.py | 23 +++++++++ .../cloud/vision_v1/types/product_search.py | 4 ++ .../vision_v1/types/product_search_service.py | 26 ++++++++++ .../cloud/vision_v1/types/text_annotation.py | 7 +++ google/cloud/vision_v1/types/web_detection.py | 5 ++ .../services/image_annotator/async_client.py | 6 +++ .../services/image_annotator/client.py | 18 +++++-- .../image_annotator/transports/base.py | 9 ++++ .../image_annotator/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../cloud/vision_v1p1beta1/types/geometry.py | 1 + .../vision_v1p1beta1/types/image_annotator.py | 14 ++++++ .../vision_v1p1beta1/types/text_annotation.py | 7 +++ .../vision_v1p1beta1/types/web_detection.py | 5 ++ .../services/image_annotator/async_client.py | 6 +++ .../services/image_annotator/client.py | 18 +++++-- .../image_annotator/transports/base.py | 9 ++++ .../image_annotator/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../cloud/vision_v1p2beta1/types/geometry.py | 1 + .../vision_v1p2beta1/types/image_annotator.py | 19 +++++++ .../vision_v1p2beta1/types/text_annotation.py | 7 +++ .../vision_v1p2beta1/types/web_detection.py | 5 ++ .../services/image_annotator/async_client.py | 6 +++ .../services/image_annotator/client.py | 18 +++++-- .../image_annotator/transports/base.py | 9 ++++ .../image_annotator/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../services/product_search/async_client.py | 6 +++ .../services/product_search/client.py | 18 +++++-- .../product_search/transports/base.py | 9 ++++ .../product_search/transports/grpc.py | 3 ++ .../product_search/transports/grpc_asyncio.py | 3 ++ .../cloud/vision_v1p3beta1/types/geometry.py | 2 + .../vision_v1p3beta1/types/image_annotator.py | 20 ++++++++ .../vision_v1p3beta1/types/product_search.py | 4 ++ .../types/product_search_service.py | 25 ++++++++++ .../vision_v1p3beta1/types/text_annotation.py | 7 +++ .../vision_v1p3beta1/types/web_detection.py | 5 ++ .../services/image_annotator/async_client.py | 6 +++ .../services/image_annotator/client.py | 18 +++++-- .../image_annotator/transports/base.py | 9 ++++ .../image_annotator/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../services/product_search/async_client.py | 6 +++ .../services/product_search/client.py | 18 +++++-- .../product_search/transports/base.py | 9 ++++ .../product_search/transports/grpc.py | 3 ++ .../product_search/transports/grpc_asyncio.py | 3 ++ google/cloud/vision_v1p4beta1/types/face.py | 3 ++ .../cloud/vision_v1p4beta1/types/geometry.py | 1 + .../vision_v1p4beta1/types/image_annotator.py | 23 +++++++++ .../vision_v1p4beta1/types/product_search.py | 4 ++ .../types/product_search_service.py | 26 ++++++++++ .../vision_v1p4beta1/types/text_annotation.py | 7 +++ .../vision_v1p4beta1/types/web_detection.py | 5 ++ .../gapic/vision_v1/test_image_annotator.py | 50 +++++++++++++++++++ .../gapic/vision_v1/test_product_search.py | 50 +++++++++++++++++++ .../vision_v1p1beta1/test_image_annotator.py | 50 +++++++++++++++++++ .../vision_v1p2beta1/test_image_annotator.py | 50 +++++++++++++++++++ .../vision_v1p3beta1/test_image_annotator.py | 50 +++++++++++++++++++ .../vision_v1p3beta1/test_product_search.py | 50 +++++++++++++++++++ .../vision_v1p4beta1/test_image_annotator.py | 50 +++++++++++++++++++ .../vision_v1p4beta1/test_product_search.py | 50 +++++++++++++++++++ 75 files changed, 937 insertions(+), 32 deletions(-) diff --git a/google/cloud/vision_v1/services/image_annotator/async_client.py b/google/cloud/vision_v1/services/image_annotator/async_client.py index 311d3df4..0bbb1767 100644 --- a/google/cloud/vision_v1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1/services/image_annotator/async_client.py @@ -525,6 +525,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/image_annotator/client.py b/google/cloud/vision_v1/services/image_annotator/client.py index 122c1ed4..27a199d2 100644 --- a/google/cloud/vision_v1/services/image_annotator/client.py +++ b/google/cloud/vision_v1/services/image_annotator/client.py @@ -365,10 +365,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -704,6 +701,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/image_annotator/transports/base.py b/google/cloud/vision_v1/services/image_annotator/transports/base.py index bf88d098..d151cd5a 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/base.py @@ -219,6 +219,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py index 666c5d3c..42f6671c 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py @@ -384,5 +384,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py index 930bb66f..17a5d34f 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py @@ -391,5 +391,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1/services/product_search/async_client.py b/google/cloud/vision_v1/services/product_search/async_client.py index e8c3bdb8..4da3f2ff 100644 --- a/google/cloud/vision_v1/services/product_search/async_client.py +++ b/google/cloud/vision_v1/services/product_search/async_client.py @@ -2080,6 +2080,12 @@ async def purge_products( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/product_search/client.py b/google/cloud/vision_v1/services/product_search/client.py index ece2329b..7169a753 100644 --- a/google/cloud/vision_v1/services/product_search/client.py +++ b/google/cloud/vision_v1/services/product_search/client.py @@ -404,10 +404,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def create_product_set( @@ -2141,6 +2138,19 @@ def purge_products( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/product_search/transports/base.py b/google/cloud/vision_v1/services/product_search/transports/base.py index a6ae5112..4569d29a 100644 --- a/google/cloud/vision_v1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1/services/product_search/transports/base.py @@ -430,6 +430,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc.py b/google/cloud/vision_v1/services/product_search/transports/grpc.py index df926905..f35155a4 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1/services/product_search/transports/grpc.py @@ -951,5 +951,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + self.grpc_channel.close() + __all__ = ("ProductSearchGrpcTransport",) diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py index 95dcc826..6713950d 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py @@ -968,5 +968,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ProductSearchGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1/types/geometry.py b/google/cloud/vision_v1/types/geometry.py index c30f0162..47731f18 100644 --- a/google/cloud/vision_v1/types/geometry.py +++ b/google/cloud/vision_v1/types/geometry.py @@ -56,6 +56,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1/types/image_annotator.py b/google/cloud/vision_v1/types/image_annotator.py index 6ae4d5ae..2570e8ca 100644 --- a/google/cloud/vision_v1/types/image_annotator.py +++ b/google/cloud/vision_v1/types/image_annotator.py @@ -164,6 +164,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -242,6 +243,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -317,6 +319,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -327,6 +330,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -343,6 +347,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -398,6 +403,7 @@ class EntityAnnotation(proto.Message): class LocalizedObjectAnnotation(proto.Message): r"""Set of detected objects with bounding boxes. + Attributes: mid (str): Object ID that should align with @@ -484,6 +490,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -516,6 +523,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1.types.ColorInfo]): RGB color values with their score and pixel @@ -527,6 +535,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -573,6 +582,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -590,6 +600,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -615,6 +626,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1.types.LatLongRect): Not used. @@ -694,6 +706,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1.types.FaceAnnotation]): If present, face detection has completed @@ -814,6 +827,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -922,6 +936,7 @@ class BatchAnnotateFilesRequest(proto.Message): class BatchAnnotateFilesResponse(proto.Message): r"""A list of file annotation responses. + Attributes: responses (Sequence[google.cloud.vision_v1.types.AnnotateFileResponse]): The list of file annotation responses, each @@ -937,6 +952,7 @@ class BatchAnnotateFilesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1.types.InputConfig): Required. Information about the input file. @@ -958,6 +974,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1.types.OutputConfig): The output location and metadata from @@ -969,6 +986,7 @@ class AsyncAnnotateFileResponse(proto.Message): class AsyncBatchAnnotateImagesRequest(proto.Message): r"""Request for async image annotation for a list of images. + Attributes: requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): Required. Individual image annotation @@ -1000,6 +1018,7 @@ class AsyncBatchAnnotateImagesRequest(proto.Message): class AsyncBatchAnnotateImagesResponse(proto.Message): r"""Response to an async batch image annotation request. + Attributes: output_config (google.cloud.vision_v1.types.OutputConfig): The output location and metadata from @@ -1040,6 +1059,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -1054,6 +1074,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1.types.GcsSource): The Google Cloud Storage location to read the @@ -1079,6 +1100,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1.types.GcsDestination): The Google Cloud Storage location to write @@ -1154,6 +1176,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1/types/product_search.py b/google/cloud/vision_v1/types/product_search.py index 17364f24..7d09aecd 100644 --- a/google/cloud/vision_v1/types/product_search.py +++ b/google/cloud/vision_v1/types/product_search.py @@ -28,6 +28,7 @@ class ProductSearchParams(proto.Message): r"""Parameters for a product search request. + Attributes: bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The bounding polygon around the area of @@ -74,6 +75,7 @@ class ProductSearchParams(proto.Message): class ProductSearchResults(proto.Message): r"""Results for a product search request. + Attributes: index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these @@ -93,6 +95,7 @@ class ProductSearchResults(proto.Message): class Result(proto.Message): r"""Information about a product. + Attributes: product (google.cloud.vision_v1.types.Product): The Product. @@ -112,6 +115,7 @@ class Result(proto.Message): class ObjectAnnotation(proto.Message): r"""Prediction for what the object in the bounding box is. + Attributes: mid (str): Object ID that should align with diff --git a/google/cloud/vision_v1/types/product_search_service.py b/google/cloud/vision_v1/types/product_search_service.py index 269230e9..d3844e2c 100644 --- a/google/cloud/vision_v1/types/product_search_service.py +++ b/google/cloud/vision_v1/types/product_search_service.py @@ -61,6 +61,7 @@ class Product(proto.Message): r"""A Product contains ReferenceImages. + Attributes: name (str): The resource name of the product. @@ -104,6 +105,7 @@ class Product(proto.Message): class KeyValue(proto.Message): r"""A product label represented as a key-value pair. + Attributes: key (str): The key of the label attached to the product. @@ -204,6 +206,7 @@ class ReferenceImage(proto.Message): class CreateProductRequest(proto.Message): r"""Request message for the ``CreateProduct`` method. + Attributes: parent (str): Required. The project in which the Product should be @@ -227,6 +230,7 @@ class CreateProductRequest(proto.Message): class ListProductsRequest(proto.Message): r"""Request message for the ``ListProducts`` method. + Attributes: parent (str): Required. The project OR ProductSet from which Products @@ -248,6 +252,7 @@ class ListProductsRequest(proto.Message): class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. + Attributes: products (Sequence[google.cloud.vision_v1.types.Product]): List of products. @@ -267,6 +272,7 @@ def raw_page(self): class GetProductRequest(proto.Message): r"""Request message for the ``GetProduct`` method. + Attributes: name (str): Required. Resource name of the Product to get. @@ -280,6 +286,7 @@ class GetProductRequest(proto.Message): class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. + Attributes: product (google.cloud.vision_v1.types.Product): Required. The Product resource which replaces @@ -300,6 +307,7 @@ class UpdateProductRequest(proto.Message): class DeleteProductRequest(proto.Message): r"""Request message for the ``DeleteProduct`` method. + Attributes: name (str): Required. Resource name of product to delete. @@ -313,6 +321,7 @@ class DeleteProductRequest(proto.Message): class CreateProductSetRequest(proto.Message): r"""Request message for the ``CreateProductSet`` method. + Attributes: parent (str): Required. The project in which the ProductSet should be @@ -336,6 +345,7 @@ class CreateProductSetRequest(proto.Message): class ListProductSetsRequest(proto.Message): r"""Request message for the ``ListProductSets`` method. + Attributes: parent (str): Required. The project from which ProductSets should be @@ -357,6 +367,7 @@ class ListProductSetsRequest(proto.Message): class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. + Attributes: product_sets (Sequence[google.cloud.vision_v1.types.ProductSet]): List of ProductSets. @@ -376,6 +387,7 @@ def raw_page(self): class GetProductSetRequest(proto.Message): r"""Request message for the ``GetProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to get. @@ -389,6 +401,7 @@ class GetProductSetRequest(proto.Message): class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. + Attributes: product_set (google.cloud.vision_v1.types.ProductSet): Required. The ProductSet resource which @@ -408,6 +421,7 @@ class UpdateProductSetRequest(proto.Message): class DeleteProductSetRequest(proto.Message): r"""Request message for the ``DeleteProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to delete. @@ -421,6 +435,7 @@ class DeleteProductSetRequest(proto.Message): class CreateReferenceImageRequest(proto.Message): r"""Request message for the ``CreateReferenceImage`` method. + Attributes: parent (str): Required. Resource name of the product in which to create @@ -446,6 +461,7 @@ class CreateReferenceImageRequest(proto.Message): class ListReferenceImagesRequest(proto.Message): r"""Request message for the ``ListReferenceImages`` method. + Attributes: parent (str): Required. Resource name of the product containing the @@ -471,6 +487,7 @@ class ListReferenceImagesRequest(proto.Message): class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. + Attributes: reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): The list of reference images. @@ -495,6 +512,7 @@ def raw_page(self): class GetReferenceImageRequest(proto.Message): r"""Request message for the ``GetReferenceImage`` method. + Attributes: name (str): Required. The resource name of the ReferenceImage to get. @@ -508,6 +526,7 @@ class GetReferenceImageRequest(proto.Message): class DeleteReferenceImageRequest(proto.Message): r"""Request message for the ``DeleteReferenceImage`` method. + Attributes: name (str): Required. The resource name of the reference image to @@ -522,6 +541,7 @@ class DeleteReferenceImageRequest(proto.Message): class AddProductToProductSetRequest(proto.Message): r"""Request message for the ``AddProductToProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -542,6 +562,7 @@ class AddProductToProductSetRequest(proto.Message): class RemoveProductFromProductSetRequest(proto.Message): r"""Request message for the ``RemoveProductFromProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -562,6 +583,7 @@ class RemoveProductFromProductSetRequest(proto.Message): class ListProductsInProductSetRequest(proto.Message): r"""Request message for the ``ListProductsInProductSet`` method. + Attributes: name (str): Required. The ProductSet resource for which to retrieve @@ -584,6 +606,7 @@ class ListProductsInProductSetRequest(proto.Message): class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. + Attributes: products (Sequence[google.cloud.vision_v1.types.Product]): The list of Products. @@ -687,6 +710,7 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + Attributes: gcs_source (google.cloud.vision_v1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv @@ -701,6 +725,7 @@ class ImportProductSetsInputConfig(proto.Message): class ImportProductSetsRequest(proto.Message): r"""Request message for the ``ImportProductSets`` method. + Attributes: parent (str): Required. The project in which the ProductSets should be @@ -796,6 +821,7 @@ class ProductSetPurgeConfig(proto.Message): class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. + Attributes: product_set_purge_config (google.cloud.vision_v1.types.ProductSetPurgeConfig): Specify which ProductSet contains the diff --git a/google/cloud/vision_v1/types/text_annotation.py b/google/cloud/vision_v1/types/text_annotation.py index 224fe7c0..94643170 100644 --- a/google/cloud/vision_v1/types/text_annotation.py +++ b/google/cloud/vision_v1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1/types/web_detection.py b/google/cloud/vision_v1/types/web_detection.py index c629b85a..78bab322 100644 --- a/google/cloud/vision_v1/types/web_detection.py +++ b/google/cloud/vision_v1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -49,6 +50,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -67,6 +69,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -80,6 +83,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -112,6 +116,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py index 57a81899..79c154ff 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py @@ -238,6 +238,12 @@ async def batch_annotate_images( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py index 04025123..c3ec4ee0 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py @@ -331,10 +331,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -406,6 +403,19 @@ def batch_annotate_images( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py index ddf9be8f..60872932 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py @@ -172,6 +172,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def batch_annotate_images( self, diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py index 564c52c2..bdb337c0 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py @@ -258,5 +258,8 @@ def batch_annotate_images( ) return self._stubs["batch_annotate_images"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py index f8b7c01b..b0d0aa31 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py @@ -261,5 +261,8 @@ def batch_annotate_images( ) return self._stubs["batch_annotate_images"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p1beta1/types/geometry.py b/google/cloud/vision_v1p1beta1/types/geometry.py index bc33ea35..29d617a7 100644 --- a/google/cloud/vision_v1p1beta1/types/geometry.py +++ b/google/cloud/vision_v1p1beta1/types/geometry.py @@ -40,6 +40,7 @@ class Vertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p1beta1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1p1beta1/types/image_annotator.py b/google/cloud/vision_v1p1beta1/types/image_annotator.py index b8196484..a099dbae 100644 --- a/google/cloud/vision_v1p1beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p1beta1/types/image_annotator.py @@ -104,6 +104,7 @@ class Type(proto.Enum): class ImageSource(proto.Message): r"""External image source (Google Cloud Storage image location). + Attributes: gcs_image_uri (str): NOTE: For new code ``image_uri`` below is preferred. Google @@ -132,6 +133,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: as @@ -207,6 +209,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -280,6 +283,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -290,6 +294,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -306,6 +311,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -396,6 +402,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -428,6 +435,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p1beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -439,6 +447,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p1beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -485,6 +494,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -502,6 +512,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -527,6 +538,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p1beta1.types.LatLongRect): lat/long rectangle that specifies the @@ -583,6 +595,7 @@ class AnnotateImageRequest(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation]): If present, face detection has completed @@ -672,6 +685,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageResponse]): Individual responses to image annotation diff --git a/google/cloud/vision_v1p1beta1/types/text_annotation.py b/google/cloud/vision_v1p1beta1/types/text_annotation.py index bc458aca..f7d7c049 100644 --- a/google/cloud/vision_v1p1beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p1beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -126,6 +130,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -207,6 +212,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -240,6 +246,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p1beta1/types/web_detection.py b/google/cloud/vision_v1p1beta1/types/web_detection.py index 664f49bd..d23f94b6 100644 --- a/google/cloud/vision_v1p1beta1/types/web_detection.py +++ b/google/cloud/vision_v1p1beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -47,6 +48,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -65,6 +67,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -78,6 +81,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -110,6 +114,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py index d05d66fd..d952f873 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py @@ -332,6 +332,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py index 15ad8646..5462d846 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py @@ -333,10 +333,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -495,6 +492,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py index 1b035ec6..cd9ee952 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py @@ -189,6 +189,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py index f734a3c3..215ddf00 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py @@ -309,5 +309,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py index c7de2e83..ebab6ad9 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py @@ -315,5 +315,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p2beta1/types/geometry.py b/google/cloud/vision_v1p2beta1/types/geometry.py index c10c04b2..c441eca2 100644 --- a/google/cloud/vision_v1p2beta1/types/geometry.py +++ b/google/cloud/vision_v1p2beta1/types/geometry.py @@ -56,6 +56,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p2beta1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1p2beta1/types/image_annotator.py b/google/cloud/vision_v1p2beta1/types/image_annotator.py index 935b40af..9761a2e7 100644 --- a/google/cloud/vision_v1p2beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p2beta1/types/image_annotator.py @@ -155,6 +155,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -230,6 +231,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -303,6 +305,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -313,6 +316,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -329,6 +333,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -420,6 +425,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -452,6 +458,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p2beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -463,6 +470,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p2beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -509,6 +517,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -526,6 +535,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -551,6 +561,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p2beta1.types.LatLongRect): Not used. @@ -624,6 +635,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation]): If present, face detection has completed @@ -737,6 +749,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -750,6 +763,7 @@ class BatchAnnotateImagesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1p2beta1.types.InputConfig): Required. Information about the input file. @@ -771,6 +785,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): The output location and metadata from @@ -797,6 +812,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -811,6 +827,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1p2beta1.types.GcsSource): The Google Cloud Storage location to read the @@ -827,6 +844,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1p2beta1.types.GcsDestination): The Google Cloud Storage location to write @@ -893,6 +911,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1p2beta1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1p2beta1/types/text_annotation.py b/google/cloud/vision_v1p2beta1/types/text_annotation.py index c8e457f3..2bd6a914 100644 --- a/google/cloud/vision_v1p2beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p2beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p2beta1/types/web_detection.py b/google/cloud/vision_v1p2beta1/types/web_detection.py index 45f796f7..4ae5075b 100644 --- a/google/cloud/vision_v1p2beta1/types/web_detection.py +++ b/google/cloud/vision_v1p2beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -47,6 +48,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -65,6 +67,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -78,6 +81,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -110,6 +114,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py index 8c460024..1eeba811 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py @@ -333,6 +333,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py index 1ac9894b..30d68db0 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py @@ -365,10 +365,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -527,6 +524,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py index 2d9866fc..4aef3c5e 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py @@ -186,6 +186,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py index f017059c..db3cb8d5 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py @@ -309,5 +309,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py index ad423c81..0114a89c 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py @@ -315,5 +315,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py index 3ac90b29..f5078491 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py @@ -1962,6 +1962,12 @@ async def import_product_sets( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/product_search/client.py b/google/cloud/vision_v1p3beta1/services/product_search/client.py index 0e9e3a23..4ea43f52 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/client.py @@ -405,10 +405,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def create_product_set( @@ -2042,6 +2039,19 @@ def import_product_sets( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py index 3a408858..14afcdb7 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py @@ -406,6 +406,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py index a048c268..5c642bba 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py @@ -917,5 +917,8 @@ def import_product_sets( ) return self._stubs["import_product_sets"] + def close(self): + self.grpc_channel.close() + __all__ = ("ProductSearchGrpcTransport",) diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py index cd9326a6..83fe6924 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py @@ -933,5 +933,8 @@ def import_product_sets( ) return self._stubs["import_product_sets"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ProductSearchGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p3beta1/types/geometry.py b/google/cloud/vision_v1p3beta1/types/geometry.py index 04c7a90b..1c5e12e6 100644 --- a/google/cloud/vision_v1p3beta1/types/geometry.py +++ b/google/cloud/vision_v1p3beta1/types/geometry.py @@ -62,6 +62,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p3beta1.types.Vertex]): The bounding polygon vertices. @@ -77,6 +78,7 @@ class BoundingPoly(proto.Message): class NormalizedBoundingPoly(proto.Message): r"""A normalized bounding polygon around a portion of an image. + Attributes: vertices (Sequence[google.cloud.vision_v1p3beta1.types.NormalizedVertex]): Normalized vertices of the bounding polygon. diff --git a/google/cloud/vision_v1p3beta1/types/image_annotator.py b/google/cloud/vision_v1p3beta1/types/image_annotator.py index a0fa0b7c..aad0e4fe 100644 --- a/google/cloud/vision_v1p3beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p3beta1/types/image_annotator.py @@ -159,6 +159,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -234,6 +235,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -307,6 +309,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -317,6 +320,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -333,6 +337,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -388,6 +393,7 @@ class EntityAnnotation(proto.Message): class LocalizedObjectAnnotation(proto.Message): r"""Set of detected objects with bounding boxes. + Attributes: mid (str): Object ID that should align with @@ -450,6 +456,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -482,6 +489,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p3beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -493,6 +501,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p3beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -539,6 +548,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -556,6 +566,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -581,6 +592,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p3beta1.types.LatLongRect): Not used. @@ -659,6 +671,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation]): If present, face detection has completed @@ -785,6 +798,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -798,6 +812,7 @@ class BatchAnnotateImagesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1p3beta1.types.InputConfig): Required. Information about the input file. @@ -819,6 +834,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): The output location and metadata from @@ -845,6 +861,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -859,6 +876,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1p3beta1.types.GcsSource): The Google Cloud Storage location to read the @@ -875,6 +893,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1p3beta1.types.GcsDestination): The Google Cloud Storage location to write @@ -941,6 +960,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1p3beta1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1p3beta1/types/product_search.py b/google/cloud/vision_v1p3beta1/types/product_search.py index f96c5a38..8f565a8c 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search.py +++ b/google/cloud/vision_v1p3beta1/types/product_search.py @@ -46,6 +46,7 @@ class ProductSearchResultsView(proto.Enum): class ProductSearchParams(proto.Message): r"""Parameters for a product search request. + Attributes: catalog_name (str): The resource name of the catalog to search. @@ -109,6 +110,7 @@ class ProductSearchParams(proto.Message): class ProductSearchResults(proto.Message): r"""Results for a product search request. + Attributes: category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): Product category. [Deprecated] Use ``product_category``. @@ -128,6 +130,7 @@ class ProductSearchResults(proto.Message): class ProductInfo(proto.Message): r"""Information about a product. + Attributes: product_id (str): Product ID. @@ -150,6 +153,7 @@ class ProductInfo(proto.Message): class Result(proto.Message): r"""Information about a product. + Attributes: product (google.cloud.vision_v1p3beta1.types.Product): The Product. diff --git a/google/cloud/vision_v1p3beta1/types/product_search_service.py b/google/cloud/vision_v1p3beta1/types/product_search_service.py index c42c3bf1..de561f13 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p3beta1/types/product_search_service.py @@ -59,6 +59,7 @@ class Product(proto.Message): r"""A Product contains ReferenceImages. + Attributes: name (str): The resource name of the product. @@ -96,6 +97,7 @@ class Product(proto.Message): class KeyValue(proto.Message): r"""A product label represented as a key-value pair. + Attributes: key (str): The key of the label attached to the product. @@ -196,6 +198,7 @@ class ReferenceImage(proto.Message): class CreateProductRequest(proto.Message): r"""Request message for the ``CreateProduct`` method. + Attributes: parent (str): Required. The project in which the Product should be @@ -219,6 +222,7 @@ class CreateProductRequest(proto.Message): class ListProductsRequest(proto.Message): r"""Request message for the ``ListProducts`` method. + Attributes: parent (str): Required. The project OR ProductSet from which Products @@ -240,6 +244,7 @@ class ListProductsRequest(proto.Message): class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. + Attributes: products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): List of products. @@ -259,6 +264,7 @@ def raw_page(self): class GetProductRequest(proto.Message): r"""Request message for the ``GetProduct`` method. + Attributes: name (str): Required. Resource name of the Product to get. @@ -272,6 +278,7 @@ class GetProductRequest(proto.Message): class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. + Attributes: product (google.cloud.vision_v1p3beta1.types.Product): Required. The Product resource which replaces @@ -292,6 +299,7 @@ class UpdateProductRequest(proto.Message): class DeleteProductRequest(proto.Message): r"""Request message for the ``DeleteProduct`` method. + Attributes: name (str): Required. Resource name of product to delete. @@ -305,6 +313,7 @@ class DeleteProductRequest(proto.Message): class CreateProductSetRequest(proto.Message): r"""Request message for the ``CreateProductSet`` method. + Attributes: parent (str): Required. The project in which the ProductSet should be @@ -328,6 +337,7 @@ class CreateProductSetRequest(proto.Message): class ListProductSetsRequest(proto.Message): r"""Request message for the ``ListProductSets`` method. + Attributes: parent (str): Required. The project from which ProductSets should be @@ -349,6 +359,7 @@ class ListProductSetsRequest(proto.Message): class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. + Attributes: product_sets (Sequence[google.cloud.vision_v1p3beta1.types.ProductSet]): List of ProductSets. @@ -368,6 +379,7 @@ def raw_page(self): class GetProductSetRequest(proto.Message): r"""Request message for the ``GetProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to get. @@ -381,6 +393,7 @@ class GetProductSetRequest(proto.Message): class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. + Attributes: product_set (google.cloud.vision_v1p3beta1.types.ProductSet): Required. The ProductSet resource which @@ -400,6 +413,7 @@ class UpdateProductSetRequest(proto.Message): class DeleteProductSetRequest(proto.Message): r"""Request message for the ``DeleteProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to delete. @@ -413,6 +427,7 @@ class DeleteProductSetRequest(proto.Message): class CreateReferenceImageRequest(proto.Message): r"""Request message for the ``CreateReferenceImage`` method. + Attributes: parent (str): Required. Resource name of the product in which to create @@ -438,6 +453,7 @@ class CreateReferenceImageRequest(proto.Message): class ListReferenceImagesRequest(proto.Message): r"""Request message for the ``ListReferenceImages`` method. + Attributes: parent (str): Required. Resource name of the product containing the @@ -463,6 +479,7 @@ class ListReferenceImagesRequest(proto.Message): class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. + Attributes: reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): The list of reference images. @@ -487,6 +504,7 @@ def raw_page(self): class GetReferenceImageRequest(proto.Message): r"""Request message for the ``GetReferenceImage`` method. + Attributes: name (str): Required. The resource name of the ReferenceImage to get. @@ -501,6 +519,7 @@ class GetReferenceImageRequest(proto.Message): class DeleteReferenceImageRequest(proto.Message): r"""Request message for the ``DeleteReferenceImage`` method. + Attributes: name (str): Required. The resource name of the reference image to @@ -516,6 +535,7 @@ class DeleteReferenceImageRequest(proto.Message): class AddProductToProductSetRequest(proto.Message): r"""Request message for the ``AddProductToProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -536,6 +556,7 @@ class AddProductToProductSetRequest(proto.Message): class RemoveProductFromProductSetRequest(proto.Message): r"""Request message for the ``RemoveProductFromProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -556,6 +577,7 @@ class RemoveProductFromProductSetRequest(proto.Message): class ListProductsInProductSetRequest(proto.Message): r"""Request message for the ``ListProductsInProductSet`` method. + Attributes: name (str): Required. The ProductSet resource for which to retrieve @@ -578,6 +600,7 @@ class ListProductsInProductSetRequest(proto.Message): class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. + Attributes: products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): The list of Products. @@ -668,6 +691,7 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + Attributes: gcs_source (google.cloud.vision_v1p3beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv @@ -682,6 +706,7 @@ class ImportProductSetsInputConfig(proto.Message): class ImportProductSetsRequest(proto.Message): r"""Request message for the ``ImportProductSets`` method. + Attributes: parent (str): Required. The project in which the ProductSets should be diff --git a/google/cloud/vision_v1p3beta1/types/text_annotation.py b/google/cloud/vision_v1p3beta1/types/text_annotation.py index 8c64ea1f..89dbaea4 100644 --- a/google/cloud/vision_v1p3beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p3beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p3beta1/types/web_detection.py b/google/cloud/vision_v1p3beta1/types/web_detection.py index 608f78aa..5cd68aa4 100644 --- a/google/cloud/vision_v1p3beta1/types/web_detection.py +++ b/google/cloud/vision_v1p3beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -47,6 +48,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -65,6 +67,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -78,6 +81,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -110,6 +114,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py index 37e9e7cd..abb4106e 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py @@ -513,6 +513,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py index c55a79e6..758f47c9 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py @@ -365,10 +365,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -704,6 +701,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py index 77795b1e..b077e031 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py @@ -207,6 +207,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py index 2552c528..53c1ab22 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py @@ -384,5 +384,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py index e9a08482..41428155 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py @@ -391,5 +391,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py index 2115e0e1..cc062587 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py @@ -2065,6 +2065,12 @@ async def purge_products( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/product_search/client.py b/google/cloud/vision_v1p4beta1/services/product_search/client.py index d49f5449..8ed9fa46 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/client.py @@ -406,10 +406,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def create_product_set( @@ -2145,6 +2142,19 @@ def purge_products( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py index 306075e1..e63d65ac 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py @@ -409,6 +409,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py index 2d593894..9f96f612 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py @@ -953,5 +953,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + self.grpc_channel.close() + __all__ = ("ProductSearchGrpcTransport",) diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py index 78cb7f81..266cf36e 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py @@ -970,5 +970,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ProductSearchGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p4beta1/types/face.py b/google/cloud/vision_v1p4beta1/types/face.py index 4586f25d..99b113f0 100644 --- a/google/cloud/vision_v1p4beta1/types/face.py +++ b/google/cloud/vision_v1p4beta1/types/face.py @@ -24,6 +24,7 @@ class FaceRecognitionParams(proto.Message): r"""Parameters for a celebrity recognition request. + Attributes: celebrity_set (Sequence[str]): The resource names for one or more @@ -39,6 +40,7 @@ class FaceRecognitionParams(proto.Message): class Celebrity(proto.Message): r"""A Celebrity is a group of Faces with an identity. + Attributes: name (str): The resource name of the preloaded Celebrity. Has the format @@ -56,6 +58,7 @@ class Celebrity(proto.Message): class FaceRecognitionResult(proto.Message): r"""Information about a face's identity. + Attributes: celebrity (google.cloud.vision_v1p4beta1.types.Celebrity): The [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] diff --git a/google/cloud/vision_v1p4beta1/types/geometry.py b/google/cloud/vision_v1p4beta1/types/geometry.py index 87fc605d..ecb31d83 100644 --- a/google/cloud/vision_v1p4beta1/types/geometry.py +++ b/google/cloud/vision_v1p4beta1/types/geometry.py @@ -56,6 +56,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p4beta1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1p4beta1/types/image_annotator.py b/google/cloud/vision_v1p4beta1/types/image_annotator.py index 99e6c7b4..10d51a78 100644 --- a/google/cloud/vision_v1p4beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p4beta1/types/image_annotator.py @@ -165,6 +165,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -248,6 +249,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -324,6 +326,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -334,6 +337,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -350,6 +354,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -405,6 +410,7 @@ class EntityAnnotation(proto.Message): class LocalizedObjectAnnotation(proto.Message): r"""Set of detected objects with bounding boxes. + Attributes: mid (str): Object ID that should align with @@ -467,6 +473,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -499,6 +506,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p4beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -510,6 +518,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p4beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -556,6 +565,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -573,6 +583,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -598,6 +609,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p4beta1.types.LatLongRect): Not used. @@ -682,6 +694,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation]): If present, face detection has completed @@ -788,6 +801,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -882,6 +896,7 @@ class BatchAnnotateFilesRequest(proto.Message): class BatchAnnotateFilesResponse(proto.Message): r"""A list of file annotation responses. + Attributes: responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileResponse]): The list of file annotation responses, each @@ -897,6 +912,7 @@ class BatchAnnotateFilesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1p4beta1.types.InputConfig): Required. Information about the input file. @@ -918,6 +934,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): The output location and metadata from @@ -929,6 +946,7 @@ class AsyncAnnotateFileResponse(proto.Message): class AsyncBatchAnnotateImagesRequest(proto.Message): r"""Request for async image annotation for a list of images. + Attributes: requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): Required. Individual image annotation @@ -946,6 +964,7 @@ class AsyncBatchAnnotateImagesRequest(proto.Message): class AsyncBatchAnnotateImagesResponse(proto.Message): r"""Response to an async batch image annotation request. + Attributes: output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): The output location and metadata from @@ -972,6 +991,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -986,6 +1006,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1p4beta1.types.GcsSource): The Google Cloud Storage location to read the @@ -1011,6 +1032,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1p4beta1.types.GcsDestination): The Google Cloud Storage location to write @@ -1086,6 +1108,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1p4beta1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1p4beta1/types/product_search.py b/google/cloud/vision_v1p4beta1/types/product_search.py index b69426bf..08065000 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search.py +++ b/google/cloud/vision_v1p4beta1/types/product_search.py @@ -28,6 +28,7 @@ class ProductSearchParams(proto.Message): r"""Parameters for a product search request. + Attributes: bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding polygon around the area of @@ -74,6 +75,7 @@ class ProductSearchParams(proto.Message): class ProductSearchResults(proto.Message): r"""Results for a product search request. + Attributes: index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these @@ -93,6 +95,7 @@ class ProductSearchResults(proto.Message): class Result(proto.Message): r"""Information about a product. + Attributes: product (google.cloud.vision_v1p4beta1.types.Product): The Product. @@ -112,6 +115,7 @@ class Result(proto.Message): class ObjectAnnotation(proto.Message): r"""Prediction for what the object in the bounding box is. + Attributes: mid (str): Object ID that should align with diff --git a/google/cloud/vision_v1p4beta1/types/product_search_service.py b/google/cloud/vision_v1p4beta1/types/product_search_service.py index 28dc7191..31c39977 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p4beta1/types/product_search_service.py @@ -61,6 +61,7 @@ class Product(proto.Message): r"""A Product contains ReferenceImages. + Attributes: name (str): The resource name of the product. @@ -103,6 +104,7 @@ class Product(proto.Message): class KeyValue(proto.Message): r"""A product label represented as a key-value pair. + Attributes: key (str): The key of the label attached to the product. @@ -204,6 +206,7 @@ class ReferenceImage(proto.Message): class CreateProductRequest(proto.Message): r"""Request message for the ``CreateProduct`` method. + Attributes: parent (str): Required. The project in which the Product should be @@ -227,6 +230,7 @@ class CreateProductRequest(proto.Message): class ListProductsRequest(proto.Message): r"""Request message for the ``ListProducts`` method. + Attributes: parent (str): Required. The project OR ProductSet from which Products @@ -248,6 +252,7 @@ class ListProductsRequest(proto.Message): class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. + Attributes: products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): List of products. @@ -267,6 +272,7 @@ def raw_page(self): class GetProductRequest(proto.Message): r"""Request message for the ``GetProduct`` method. + Attributes: name (str): Required. Resource name of the Product to get. @@ -280,6 +286,7 @@ class GetProductRequest(proto.Message): class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. + Attributes: product (google.cloud.vision_v1p4beta1.types.Product): Required. The Product resource which replaces @@ -300,6 +307,7 @@ class UpdateProductRequest(proto.Message): class DeleteProductRequest(proto.Message): r"""Request message for the ``DeleteProduct`` method. + Attributes: name (str): Required. Resource name of product to delete. @@ -313,6 +321,7 @@ class DeleteProductRequest(proto.Message): class CreateProductSetRequest(proto.Message): r"""Request message for the ``CreateProductSet`` method. + Attributes: parent (str): Required. The project in which the ProductSet should be @@ -336,6 +345,7 @@ class CreateProductSetRequest(proto.Message): class ListProductSetsRequest(proto.Message): r"""Request message for the ``ListProductSets`` method. + Attributes: parent (str): Required. The project from which ProductSets should be @@ -357,6 +367,7 @@ class ListProductSetsRequest(proto.Message): class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. + Attributes: product_sets (Sequence[google.cloud.vision_v1p4beta1.types.ProductSet]): List of ProductSets. @@ -376,6 +387,7 @@ def raw_page(self): class GetProductSetRequest(proto.Message): r"""Request message for the ``GetProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to get. @@ -389,6 +401,7 @@ class GetProductSetRequest(proto.Message): class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. + Attributes: product_set (google.cloud.vision_v1p4beta1.types.ProductSet): Required. The ProductSet resource which @@ -408,6 +421,7 @@ class UpdateProductSetRequest(proto.Message): class DeleteProductSetRequest(proto.Message): r"""Request message for the ``DeleteProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to delete. @@ -421,6 +435,7 @@ class DeleteProductSetRequest(proto.Message): class CreateReferenceImageRequest(proto.Message): r"""Request message for the ``CreateReferenceImage`` method. + Attributes: parent (str): Required. Resource name of the product in which to create @@ -446,6 +461,7 @@ class CreateReferenceImageRequest(proto.Message): class ListReferenceImagesRequest(proto.Message): r"""Request message for the ``ListReferenceImages`` method. + Attributes: parent (str): Required. Resource name of the product containing the @@ -471,6 +487,7 @@ class ListReferenceImagesRequest(proto.Message): class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. + Attributes: reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): The list of reference images. @@ -495,6 +512,7 @@ def raw_page(self): class GetReferenceImageRequest(proto.Message): r"""Request message for the ``GetReferenceImage`` method. + Attributes: name (str): Required. The resource name of the ReferenceImage to get. @@ -509,6 +527,7 @@ class GetReferenceImageRequest(proto.Message): class DeleteReferenceImageRequest(proto.Message): r"""Request message for the ``DeleteReferenceImage`` method. + Attributes: name (str): Required. The resource name of the reference image to @@ -524,6 +543,7 @@ class DeleteReferenceImageRequest(proto.Message): class AddProductToProductSetRequest(proto.Message): r"""Request message for the ``AddProductToProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -544,6 +564,7 @@ class AddProductToProductSetRequest(proto.Message): class RemoveProductFromProductSetRequest(proto.Message): r"""Request message for the ``RemoveProductFromProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -564,6 +585,7 @@ class RemoveProductFromProductSetRequest(proto.Message): class ListProductsInProductSetRequest(proto.Message): r"""Request message for the ``ListProductsInProductSet`` method. + Attributes: name (str): Required. The ProductSet resource for which to retrieve @@ -586,6 +608,7 @@ class ListProductsInProductSetRequest(proto.Message): class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. + Attributes: products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): The list of Products. @@ -689,6 +712,7 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + Attributes: gcs_source (google.cloud.vision_v1p4beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv @@ -703,6 +727,7 @@ class ImportProductSetsInputConfig(proto.Message): class ImportProductSetsRequest(proto.Message): r"""Request message for the ``ImportProductSets`` method. + Attributes: parent (str): Required. The project in which the ProductSets should be @@ -798,6 +823,7 @@ class ProductSetPurgeConfig(proto.Message): class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. + Attributes: product_set_purge_config (google.cloud.vision_v1p4beta1.types.ProductSetPurgeConfig): Specify which ProductSet contains the diff --git a/google/cloud/vision_v1p4beta1/types/text_annotation.py b/google/cloud/vision_v1p4beta1/types/text_annotation.py index 4fa23fa0..699c7111 100644 --- a/google/cloud/vision_v1p4beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p4beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p4beta1/types/web_detection.py b/google/cloud/vision_v1p4beta1/types/web_detection.py index b843b5da..a1ecc0b2 100644 --- a/google/cloud/vision_v1p4beta1/types/web_detection.py +++ b/google/cloud/vision_v1p4beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -49,6 +50,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -67,6 +69,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -80,6 +83,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -112,6 +116,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/tests/unit/gapic/vision_v1/test_image_annotator.py b/tests/unit/gapic/vision_v1/test_image_annotator.py index e0315a8a..da4a490d 100644 --- a/tests/unit/gapic/vision_v1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1/test_image_annotator.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorAsyncClient @@ -1401,6 +1402,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1959,3 +1963,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1/test_product_search.py b/tests/unit/gapic/vision_v1/test_product_search.py index c2b64a18..35c5b80d 100644 --- a/tests/unit/gapic/vision_v1/test_product_search.py +++ b/tests/unit/gapic/vision_v1/test_product_search.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1.services.product_search import ProductSearchAsyncClient @@ -5533,6 +5534,9 @@ def test_product_search_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -6120,3 +6124,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py index 618d0077..a4c35d71 100644 --- a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p1beta1.services.image_annotator import ( @@ -785,6 +786,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): @@ -1264,3 +1268,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py index f362962a..3dc9c74c 100644 --- a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p2beta1.services.image_annotator import ( @@ -992,6 +993,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1502,3 +1506,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py index 2a5466e9..8dea7855 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p3beta1.services.image_annotator import ( @@ -994,6 +995,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1552,3 +1556,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py index b6595a2f..09a0c8fe 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p3beta1.services.product_search import ( @@ -5333,6 +5334,9 @@ def test_product_search_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -5920,3 +5924,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py index 4b8f2214..aab0a04f 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p4beta1.services.image_annotator import ( @@ -1404,6 +1405,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1962,3 +1966,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py index 969b8b08..afc237d2 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p4beta1.services.product_search import ( @@ -5535,6 +5536,9 @@ def test_product_search_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -6122,3 +6126,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called()