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 #944

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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