-
Notifications
You must be signed in to change notification settings - Fork 7
chore: add method documentation #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
04c0fae
add docstrings to Momento class methods
poppoerika cbc1f80
add docstrings to Cache class methods
poppoerika 1d9a7a3
add docstrings to cache operation responses' classes' methods
poppoerika 9265939
fix typos and update docstrings
poppoerika 4476ca8
remove SdkError from Raises
poppoerika 0ce36a0
update Raises section to match only possible errors thrown
poppoerika File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,21 +11,40 @@ class CacheResult(Enum): | |
|
|
||
| class CacheSetResponse: | ||
| def __init__(self, grpc_set_response, value): | ||
| """Initializes CacheSetResponse to handle gRPC set response. | ||
|
|
||
| Args: | ||
| grpc_set_response: Protobuf based response returned by Scs. | ||
| value (string or bytes): The value to be used to store item in the cache | ||
|
|
||
| Raises: | ||
| InternalServerError: If server encountered an unknown error while trying to store the item. | ||
| """ | ||
| self._value = value | ||
| if (grpc_set_response.result != cache_client_types.Ok): | ||
| _momento_logger.debug(f'Set received unsupported ECacheResult {grpc_set_response.result}') | ||
| raise error_converter.convert_ecache_result( | ||
| grpc_set_response.result, grpc_set_response.message, 'SET') | ||
|
|
||
| def str_utf8(self): | ||
| """Decodes string value set in cache to a utf-8 string.""" | ||
| return self._value.decode('utf-8') | ||
|
|
||
| def bytes(self): | ||
| """Returns byte value set in cache.""" | ||
| return self._value | ||
|
|
||
|
|
||
| class CacheGetResponse: | ||
| def __init__(self, grpc_get_response): | ||
| """Initializes CacheGetResponse to handle gRPC get response. | ||
|
|
||
| Args: | ||
| grpc_get_response: Protobuf based response returned by Scs. | ||
|
|
||
| Raises: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: please verify if these errors will ever come from this method. |
||
| InternalServerError: If server encountered an unknown error while trying to retrieve the item. | ||
| """ | ||
| self._value = grpc_get_response.cache_body | ||
|
|
||
| if (grpc_get_response.result == cache_client_types.Hit): | ||
|
|
@@ -39,16 +58,19 @@ def __init__(self, grpc_get_response): | |
|
|
||
|
|
||
| def str_utf8(self): | ||
| """Returns value stored in cache as utf-8 string if there was Hit. Returns None otherwise.""" | ||
| if (self._result == CacheResult.HIT): | ||
| return self._value.decode('utf-8') | ||
| return None | ||
|
|
||
| def bytes(self): | ||
| """Returns value stored in cache as bytes if there was Hit. Returns None otherwise.""" | ||
| if (self._result == CacheResult.HIT): | ||
| return self._value | ||
| return None | ||
|
|
||
| def result(self): | ||
| """Returns get operation result such as HIT or MISS.""" | ||
| return self._result | ||
|
|
||
|
|
||
|
|
@@ -64,21 +86,34 @@ def __init__(self, grpc_delete_cache_response): | |
|
|
||
| class ListCachesResponse: | ||
| def __init__(self, grpc_list_cache_response): | ||
| """Initializes ListCacheResponse to handle list cache response. | ||
|
|
||
| Args: | ||
| grpc_list_cache_response: Protobuf based response returned by Scs. | ||
| """ | ||
| self._next_token = grpc_list_cache_response.next_token if grpc_list_cache_response.next_token != '' else None | ||
| self._caches = [] | ||
| for cache in grpc_list_cache_response.cache: | ||
| self._caches.append(CacheInfo(cache)) | ||
|
|
||
| def next_token(self): | ||
| """Returns next token.""" | ||
| return self._next_token | ||
|
|
||
| def caches(self): | ||
| """Returns all caches.""" | ||
| return self._caches | ||
|
|
||
|
|
||
| class CacheInfo: | ||
| def __init__(self, grpc_listed_caches): | ||
| self._name = grpc_listed_caches.cache_name | ||
| def __init__(self, grpc_listed_cache): | ||
| """Initializes CacheInfo to handle caches returned from list cache operation. | ||
|
|
||
| Args: | ||
| grpc_listed_cache: Protobuf based response returned by Scs. | ||
| """ | ||
| self._name = grpc_listed_cache.cache_name | ||
|
|
||
| def name(self): | ||
| """Returns all cache's name.""" | ||
| return self._name | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 doubt if all these errors will be thrown. Can you verify? All I think will come on initialize is InternalServerError from call to error_converter.convert_ecache_result