Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add async context manager return types #828

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,7 @@ async def list_hot_tablets(
# Done; return the response.
return response

async def __aenter__(self):
async def __aenter__(self) -> "BigtableInstanceAdminAsyncClient":
return self

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

async def __aenter__(self):
async def __aenter__(self) -> "BigtableTableAdminAsyncClient":
return self

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ def read_change_stream(
# Done; return the response.
return response

async def __aenter__(self):
async def __aenter__(self) -> "BigtableAsyncClient":
return self

async def __aexit__(self, exc_type, exc, tb):
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/bigtable_v2/types/bigtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ReadRowsRequest(proto.Message):
request_stats_view (google.cloud.bigtable_v2.types.ReadRowsRequest.RequestStatsView):
The view into RequestStats, as described
above.
reversed_ (bool):
reversed (bool):
Experimental API - Please note that this API is currently
experimental and can change in the future.

Expand Down Expand Up @@ -139,7 +139,7 @@ class RequestStatsView(proto.Enum):
number=6,
enum=RequestStatsView,
)
reversed_: bool = proto.Field(
reversed: bool = proto.Field(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not yet released (See #827)

proto.BOOL,
number=7,
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/fixup_bigtable_v2_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class bigtableCallTransformer(cst.CSTTransformer):
'ping_and_warm': ('name', 'app_profile_id', ),
'read_change_stream': ('table_name', 'app_profile_id', 'partition', 'start_time', 'continuation_tokens', 'end_time', 'heartbeat_duration', ),
'read_modify_write_row': ('table_name', 'row_key', 'rules', 'app_profile_id', ),
'read_rows': ('table_name', 'app_profile_id', 'rows', 'filter', 'rows_limit', 'request_stats_view', 'reversed_', ),
'read_rows': ('table_name', 'app_profile_id', 'rows', 'filter', 'rows_limit', 'request_stats_view', 'reversed', ),
'sample_row_keys': ('table_name', 'app_profile_id', ),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2425,11 +2425,6 @@ def test_get_cluster(request_type, transport: str = "grpc"):
state=instance.Cluster.State.READY,
serve_nodes=1181,
default_storage_type=common.StorageType.SSD,
cluster_config=instance.Cluster.ClusterConfig(
cluster_autoscaling_config=instance.Cluster.ClusterAutoscalingConfig(
autoscaling_limits=instance.AutoscalingLimits(min_serve_nodes=1600)
)
),
)
response = client.get_cluster(request)

Expand Down Expand Up @@ -3529,9 +3524,6 @@ def test_create_app_profile(request_type, transport: str = "grpc"):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)
response = client.create_app_profile(request)

Expand Down Expand Up @@ -3801,9 +3793,6 @@ def test_get_app_profile(request_type, transport: str = "grpc"):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)
response = client.get_app_profile(request)

Expand Down Expand Up @@ -4456,9 +4445,11 @@ async def test_list_app_profiles_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_app_profiles(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -6138,9 +6129,11 @@ async def test_list_hot_tablets_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_hot_tablets(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -8088,11 +8081,6 @@ def test_get_cluster_rest(request_type):
state=instance.Cluster.State.READY,
serve_nodes=1181,
default_storage_type=common.StorageType.SSD,
cluster_config=instance.Cluster.ClusterConfig(
cluster_autoscaling_config=instance.Cluster.ClusterAutoscalingConfig(
autoscaling_limits=instance.AutoscalingLimits(min_serve_nodes=1600)
)
),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -9345,9 +9333,6 @@ def test_create_app_profile_rest(request_type):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -9670,9 +9655,6 @@ def test_get_app_profile_rest(request_type):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)

# Wrap the value into a proper Response obj
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/gapic/bigtable_admin_v2/test_bigtable_table_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,9 +1691,11 @@ async def test_list_tables_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_tables(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -4457,9 +4459,11 @@ async def test_list_snapshots_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_snapshots(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -6058,9 +6062,11 @@ async def test_list_backups_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_backups(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/gapic/bigtable_v2/test_bigtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5316,11 +5316,7 @@ def test_read_change_stream_rest(request_type):
# Mock the http request call within the method and fake a response.
with mock.patch.object(type(client.transport._session), "request") as req:
# Designate an appropriate value for the returned response.
return_value = bigtable.ReadChangeStreamResponse(
data_change=bigtable.ReadChangeStreamResponse.DataChange(
type_=bigtable.ReadChangeStreamResponse.DataChange.Type.USER
),
)
return_value = bigtable.ReadChangeStreamResponse()

# Wrap the value into a proper Response obj
response_value = Response()
Expand Down