Skip to content

Commit

Permalink
fix: Add async context manager return types (#944)
Browse files Browse the repository at this point in the history
* fix: Add async context manager return types

chore: Mock return_value should not populate oneof message fields

chore: Support snippet generation for services that only support REST transport

chore: Update gapic-generator-python to v1.11.0
PiperOrigin-RevId: 545430278

Source-Link: googleapis/googleapis@601b532

Source-Link: googleapis/googleapis-gen@b3f18d0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjNmMThkMGY2NTYwYTg1NTAyMmZkMDU4ODY1ZTc2MjA0NzlkN2FmOSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Jul 4, 2023
1 parent f54dcd0 commit a3b2061
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion google/pubsub_v1/services/publisher/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
4 changes: 2 additions & 2 deletions google/pubsub_v1/services/publisher/transports/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1572,7 +1572,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
2 changes: 1 addition & 1 deletion google/pubsub_v1/services/schema_service/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
4 changes: 2 additions & 2 deletions google/pubsub_v1/services/schema_service/transports/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1723,7 +1723,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
2 changes: 1 addition & 1 deletion google/pubsub_v1/services/subscriber/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
4 changes: 2 additions & 2 deletions google/pubsub_v1/services/subscriber/transports/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -2328,7 +2328,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
18 changes: 12 additions & 6 deletions tests/unit/gapic/pubsub_v1/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,9 +2061,11 @@ async def test_list_topics_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_topics(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 @@ -2507,9 +2509,11 @@ async def test_list_topic_subscriptions_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_topic_subscriptions(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 @@ -2953,9 +2957,11 @@ async def test_list_topic_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_topic_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
12 changes: 8 additions & 4 deletions tests/unit/gapic/pubsub_v1/test_schema_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,9 +1626,11 @@ async def test_list_schemas_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_schemas(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 @@ -2068,9 +2070,11 @@ async def test_list_schema_revisions_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_schema_revisions(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
12 changes: 8 additions & 4 deletions tests/unit/gapic/pubsub_v1/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,9 +1975,11 @@ async def test_list_subscriptions_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_subscriptions(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 @@ -3905,9 +3907,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

0 comments on commit a3b2061

Please sign in to comment.