-
Notifications
You must be signed in to change notification settings - Fork 130
Integrate _OperationFuture into Python LRO #891
Conversation
Current coverage is 82.87% (diff: 82.35%)@@ master #891 diff @@
==========================================
Files 334 334
Lines 12979 13001 +22
Methods 0 0
Messages 0 0
Branches 1706 1712 +6
==========================================
+ Hits 10759 10775 +16
- Misses 1784 1789 +5
- Partials 436 437 +1
|
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.
You should also add some usage information to the example of methods returning an OperationFuture.
@landrito Something like this? >>> from google.cloud.gapic.example.library.v1 import library_service_client
>>> api = library_service_client.LibraryServiceClient()
>>> name = api.book_path('[SHELF_ID]', '[BOOK_ID]')
>>> response = api.get_big_book(name)
>>> response.add_done_callback(do_something_with) |
A bit more verbose. This is what the example is for Ruby. For python I'd imagine it to look like. from google.cloud.gapic.example.library.v1 import library_service_client
api = library_service_client.LibraryServiceClient()
name = api.book_path('[SHELF_ID]', '[BOOK_ID]')
operation_future = api.get_big_book(name)
def callback(operation_future):
# Handle response.
result = operation_future.result
operation_future.add_done_callback(callback)
# Handle metadata.
metadata = operation_future.metadata edit: fix error. |
@@ -233,6 +233,17 @@ public String addImportLocal(String moduleName, String attributeName) { | |||
return addImport(ImportType.APP, moduleName, attributeName).shortName(); | |||
} | |||
|
|||
/** Add an import for the proto associated with the given type. */ | |||
private PythonImport addImportForType(TypeRef type) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Other than the need for documentation, this looks fine to me. Ernest's more verbose version is slightly erroneous (it should read operation_future.add_done_callback(callback)
, and should probably use a different variable name for the callback argument itself) but seems fine in principle. I also think explanatory comments on documentation like that is really useful, even if they seem like overkill to us.
Fixes potential NPE if called with a type that is not a MessageType.
PTAL |
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, but please wait to merge until the GAX change is submitted.
* Integrate _OperationFuture into Python LRO * Add LRO specific usage for method sample * Change addImportForType to addImportForMessage. Fixes potential NPE if called with a type that is not a MessageType.
Implements LRO for Python.
Depends on googleapis/gax-python#142 to generate functioning code.