GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: AsyncIO Integration [Part 3] by lidizheng · Pull Request #29 · googleapis/python-api-core

This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Conversation

@lidizheng

@lidizheng lidizheng commented May 18, 2020

Copy link
Copy Markdown
Contributor

Children PR of #26 and #28.

This PR includes AsyncIO version of:

  • LRO client
  • gRPC wrappers & helpers

Related #23

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 18, 2020
@lidizheng
lidizheng marked this pull request as ready for review May 18, 2020 22:34
@busunkim96
busunkim96 requested review from busunkim96 and software-dov May 27, 2020 00:28
busunkim96
busunkim96 reviewed May 27, 2020
View reviewed changes
Comment thread google/api_core/grpc_helpers_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/api_core/grpc_helpers_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/api_core/grpc_helpers_async.py
Comment on lines +237 to +270
class FakeUnaryUnaryCall(_WrappedUnaryUnaryCall):
"""Fake implementation for unary-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response


class FakeStreamUnaryCall(_WrappedStreamUnaryCall):
"""Fake implementation for stream-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response

async def wait_for_connection(self):
pass

@busunkim96 busunkim96 May 27, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Are these intended for use by tests only? I'd prefer they be named Mock... instead of Fake... but don't feel too strongly about it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lidizheng lidizheng May 27, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I considered Mock... naming, but they are not magic mock objects. It might misdirect users' expectation of its behavior. I'm happy to change if you have better naming.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@busunkim96 busunkim96 May 27, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Let's leave it as is then. @software-dov do you have any thoughts here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@software-dov software-dov Jun 3, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

+1 to not mock naming, although I'm a little confused as to why they don't live in the unit test file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@busunkim96 busunkim96 Jun 3, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think leaving them here makes it easier for dependent libraries to use it in their own tests.

(HttpMock in the apiary library for instance)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@software-dov software-dov Jun 4, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think the 'correct' think to do then would be to have a testlib. I am in general not a fan of mixing test code and production code, but it's not a hill I'm willing to die on.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lidizheng
lidizheng force-pushed the aio-part-3 branch from 421ef12 to 11f63d6 Compare May 27, 2020 17:28
lidizheng
lidizheng commented May 27, 2020
View reviewed changes

@lidizheng lidizheng left a comment

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@busunkim96 Thank you for the suggestions. PTALA.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/api_core/grpc_helpers_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/api_core/grpc_helpers_async.py
Comment on lines +237 to +270
class FakeUnaryUnaryCall(_WrappedUnaryUnaryCall):
"""Fake implementation for unary-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response


class FakeStreamUnaryCall(_WrappedStreamUnaryCall):
"""Fake implementation for stream-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response

async def wait_for_connection(self):
pass

@lidizheng lidizheng May 27, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I considered Mock... naming, but they are not magic mock objects. It might misdirect users' expectation of its behavior. I'm happy to change if you have better naming.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@busunkim96 busunkim96 mentioned this pull request May 27, 2020
chore: release 1.18.0 #33
Merged
@lidizheng
lidizheng force-pushed the aio-part-3 branch from 11f63d6 to 9a8906e Compare June 2, 2020 22:09
software-dov
software-dov reviewed Jun 3, 2020
View reviewed changes
Comment thread google/api_core/gapic_v1/method_async.py Outdated
Comment on lines +42 to +45
if client_info is not None:
user_agent_metadata = [client_info.to_grpc_metadata()]
else:
user_agent_metadata = None

@software-dov software-dov Jun 3, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Style nit: what about

metadata = [client_info.to_grpc_metadata()] if client_info is not None else None

?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lidizheng lidizheng Jun 3, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good idea. Updated to the suggested style.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/api_core/grpc_helpers_async.py
Comment on lines +237 to +270
class FakeUnaryUnaryCall(_WrappedUnaryUnaryCall):
"""Fake implementation for unary-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response


class FakeStreamUnaryCall(_WrappedStreamUnaryCall):
"""Fake implementation for stream-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response

async def wait_for_connection(self):
pass

@software-dov software-dov Jun 3, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

+1 to not mock naming, although I'm a little confused as to why they don't live in the unit test file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@software-dov software-dov mentioned this pull request Jun 3, 2020
asyncio support googleapis/google-cloud-python#3103
Closed
@kamyar kamyar mentioned this pull request Jun 3, 2020
FR: Async requests firebase/firebase-admin-python#104
Open
@lidizheng
lidizheng force-pushed the aio-part-3 branch from 9a8906e to cc8dc51 Compare June 3, 2020 18:53
@lidizheng

lidizheng commented Jun 3, 2020

Copy link
Copy Markdown
Contributor Author

@software-dov PTALA.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@busunkim96

busunkim96 commented Jun 4, 2020

Copy link
Copy Markdown
Contributor

@lidizheng It looks like the unit tests need to be tweaked:

func = <function _wrap_unary_errors.<locals>.error_remapped_callable at 0x7fb165893790>
default_retry = <google.api_core.retry_async.AsyncRetry object at 0x7fb166304160>
default_timeout = <google.api_core.timeout.ExponentialTimeout object at 0x7fb1663046d0>
client_info = <google.api_core.gapic_v1.client_info.ClientInfo object at 0x7fb1664eeeb0>

    def wrap_method(
            func,
            default_retry=None,
            default_timeout=None,
            client_info=client_info.DEFAULT_CLIENT_INFO,
    ):
        """Wrap an async RPC method with common behavior.

        Returns:
            Callable: A new callable that takes optional ``retry`` and ``timeout``
                arguments and applies the common error mapping, retry, timeout,
                and metadata behavior to the low-level RPC method.
        """
        func = grpc_helpers_async.wrap_errors(func)

        metadata = [client_info.to_grpc_metadata()] if client_info is not None else None

        return general_helpers.wraps(func)(_GapicCallable(
>           func, default_retry, default_timeout, metadata=user_agent_metadata))
E       NameError: name 'user_agent_metadata' is not defined
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lidizheng
lidizheng force-pushed the aio-part-3 branch from cc8dc51 to 7778770 Compare June 4, 2020 17:07
busunkim96
busunkim96 approved these changes Jun 4, 2020
View reviewed changes
software-dov
software-dov approved these changes Jun 4, 2020
View reviewed changes

@software-dov software-dov left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM. Just one minor optional tweak and a vote from my end that the test classes be moved into a standalone test library.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/api_core/operations_v1/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@lidizheng
feat: Third batch of AsyncIO integration
7f319ab
* LRO client
* gRPC wrappers & helpers
* With unit tests & docs
@lidizheng
lidizheng force-pushed the aio-part-3 branch from 7778770 to 7f319ab Compare June 4, 2020 17:37
@busunkim96
busunkim96 merged commit 7d8d580 into googleapis:master Jun 4, 2020
gcf-merge-on-green Bot pushed a commit that referenced this pull request Jun 4, 2020
@release-please
chore: release 1.18.0 (#33)
33ab7fa
🤖 I have created a release \*beep\* \*boop\* 
---
## [1.18.0](https://www.github.com/googleapis/python-api-core/compare/v1.17.0...v1.18.0) (2020-06-04)


### Features

* [CBT-6 helper] Exposing Retry._deadline as a property ([#20](https://www.github.com/googleapis/python-api-core/issues/20)) ([7be1e59](https://www.github.com/googleapis/python-api-core/commit/7be1e59e9d75c112f346d2b76dce3dd60e3584a1))
* add client_encryped_cert_source to ClientOptions ([#31](https://www.github.com/googleapis/python-api-core/issues/31)) ([e4eaec0](https://www.github.com/googleapis/python-api-core/commit/e4eaec0ff255114138d3715280f86d34d861a6fa))
* AsyncIO Integration [Part 2] ([#28](https://www.github.com/googleapis/python-api-core/issues/28)) ([dd9b2f3](https://www.github.com/googleapis/python-api-core/commit/dd9b2f38a70e85952cc05552ec8070cdf29ddbb4)), closes [#23](https://www.github.com/googleapis/python-api-core/issues/23)
* First batch of AIO integration ([#26](https://www.github.com/googleapis/python-api-core/issues/26)) ([a82f289](https://www.github.com/googleapis/python-api-core/commit/a82f2892b8f219b82e120e6ed9f4070869c28be7))
* third batch of AsyncIO integration ([#29](https://www.github.com/googleapis/python-api-core/issues/29)) ([7d8d580](https://www.github.com/googleapis/python-api-core/commit/7d8d58075a92e93662747d36a2d55b5e9f0943e1))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
@busunkim96 busunkim96 mentioned this pull request Jun 17, 2020
WIP: AsyncIO integration #22
Closed
4 tasks
This was referenced May 30, 2025
chore(main): release 2.0.0 #822
Closed
chore(main): release 2.0.0 #823
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@software-dov software-dov software-dov approved these changes
@busunkim96 busunkim96 busunkim96 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@lidizheng @busunkim96 @software-dov @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.