Skip to content

Commit

Permalink
fix: improper types in pagers generation (#970)
Browse files Browse the repository at this point in the history
* fix: improper types in pagers generation

Generators are Iterators not Iterables https://docs.python.org/3/library/typing.html#typing.Generator

* chore: update goldens

Co-authored-by: Bu Sun Kim <[email protected]>
Co-authored-by: Bu Sun Kim <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2021
1 parent e553dc7 commit bba3eea
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{# This lives within the loop in order to ensure that this template
is empty if there are no paged methods.
#}
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple, Optional
from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator

{% filter sort_lines %}
{% for method in service.methods.values() | selectattr('paged_result_field') %}
Expand Down Expand Up @@ -65,22 +65,22 @@ class {{ method.name }}Pager:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[{{ method.output.ident }}]:
def pages(self) -> Iterator[{{ method.output.ident }}]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

{% if method.paged_result_field.map %}
def __iter__(self) -> Iterable[Tuple[str, {{ method.paged_result_field.type.fields.get('value').ident }}]]:
def __iter__(self) -> Iterator[Tuple[str, {{ method.paged_result_field.type.fields.get('value').ident }}]]:
for page in self.pages:
yield from page.{{ method.paged_result_field.name}}.items()

def get(self, key: str) -> Optional[{{ method.paged_result_field.type.fields.get('value').ident }}]:
return self._response.items.get(key)
{% else %}
def __iter__(self) -> {{ method.paged_result_field.ident | replace('Sequence', 'Iterable') }}:
def __iter__(self) -> {{ method.paged_result_field.ident | replace('Sequence', 'Iterator') }}:
for page in self.pages:
yield from page.{{ method.paged_result_field.name }}
{% endif %}
Expand Down Expand Up @@ -135,14 +135,14 @@ class {{ method.name }}AsyncPager:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[{{ method.output.ident }}]:
async def pages(self) -> AsyncIterator[{{ method.output.ident }}]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> {{ method.paged_result_field.ident | replace('Sequence', 'AsyncIterable') }}:
def __aiter__(self) -> {{ method.paged_result_field.ident | replace('Sequence', 'AsyncIterator') }}:
async def async_generator():
async for page in self.pages:
for response in page.{{ method.paged_result_field.name }}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple, Optional
from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator

from google.cloud.asset_v1.types import asset_service
from google.cloud.asset_v1.types import assets
Expand Down Expand Up @@ -63,14 +63,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[asset_service.ListAssetsResponse]:
def pages(self) -> Iterator[asset_service.ListAssetsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[assets.Asset]:
def __iter__(self) -> Iterator[assets.Asset]:
for page in self.pages:
yield from page.assets

Expand Down Expand Up @@ -122,14 +122,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[asset_service.ListAssetsResponse]:
async def pages(self) -> AsyncIterator[asset_service.ListAssetsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[assets.Asset]:
def __aiter__(self) -> AsyncIterator[assets.Asset]:
async def async_generator():
async for page in self.pages:
for response in page.assets:
Expand Down Expand Up @@ -185,14 +185,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[asset_service.SearchAllResourcesResponse]:
def pages(self) -> Iterator[asset_service.SearchAllResourcesResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[assets.ResourceSearchResult]:
def __iter__(self) -> Iterator[assets.ResourceSearchResult]:
for page in self.pages:
yield from page.results

Expand Down Expand Up @@ -244,14 +244,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[asset_service.SearchAllResourcesResponse]:
async def pages(self) -> AsyncIterator[asset_service.SearchAllResourcesResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[assets.ResourceSearchResult]:
def __aiter__(self) -> AsyncIterator[assets.ResourceSearchResult]:
async def async_generator():
async for page in self.pages:
for response in page.results:
Expand Down Expand Up @@ -307,14 +307,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[asset_service.SearchAllIamPoliciesResponse]:
def pages(self) -> Iterator[asset_service.SearchAllIamPoliciesResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[assets.IamPolicySearchResult]:
def __iter__(self) -> Iterator[assets.IamPolicySearchResult]:
for page in self.pages:
yield from page.results

Expand Down Expand Up @@ -366,14 +366,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[asset_service.SearchAllIamPoliciesResponse]:
async def pages(self) -> AsyncIterator[asset_service.SearchAllIamPoliciesResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[assets.IamPolicySearchResult]:
def __aiter__(self) -> AsyncIterator[assets.IamPolicySearchResult]:
async def async_generator():
async for page in self.pages:
for response in page.results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple, Optional
from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator

from google.cloud.logging_v2.types import logging_config

Expand Down Expand Up @@ -62,14 +62,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[logging_config.ListBucketsResponse]:
def pages(self) -> Iterator[logging_config.ListBucketsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[logging_config.LogBucket]:
def __iter__(self) -> Iterator[logging_config.LogBucket]:
for page in self.pages:
yield from page.buckets

Expand Down Expand Up @@ -121,14 +121,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[logging_config.ListBucketsResponse]:
async def pages(self) -> AsyncIterator[logging_config.ListBucketsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[logging_config.LogBucket]:
def __aiter__(self) -> AsyncIterator[logging_config.LogBucket]:
async def async_generator():
async for page in self.pages:
for response in page.buckets:
Expand Down Expand Up @@ -184,14 +184,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[logging_config.ListViewsResponse]:
def pages(self) -> Iterator[logging_config.ListViewsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[logging_config.LogView]:
def __iter__(self) -> Iterator[logging_config.LogView]:
for page in self.pages:
yield from page.views

Expand Down Expand Up @@ -243,14 +243,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[logging_config.ListViewsResponse]:
async def pages(self) -> AsyncIterator[logging_config.ListViewsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[logging_config.LogView]:
def __aiter__(self) -> AsyncIterator[logging_config.LogView]:
async def async_generator():
async for page in self.pages:
for response in page.views:
Expand Down Expand Up @@ -306,14 +306,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[logging_config.ListSinksResponse]:
def pages(self) -> Iterator[logging_config.ListSinksResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[logging_config.LogSink]:
def __iter__(self) -> Iterator[logging_config.LogSink]:
for page in self.pages:
yield from page.sinks

Expand Down Expand Up @@ -365,14 +365,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[logging_config.ListSinksResponse]:
async def pages(self) -> AsyncIterator[logging_config.ListSinksResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[logging_config.LogSink]:
def __aiter__(self) -> AsyncIterator[logging_config.LogSink]:
async def async_generator():
async for page in self.pages:
for response in page.sinks:
Expand Down Expand Up @@ -428,14 +428,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[logging_config.ListExclusionsResponse]:
def pages(self) -> Iterator[logging_config.ListExclusionsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[logging_config.LogExclusion]:
def __iter__(self) -> Iterator[logging_config.LogExclusion]:
for page in self.pages:
yield from page.exclusions

Expand Down Expand Up @@ -487,14 +487,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
async def pages(self) -> AsyncIterable[logging_config.ListExclusionsResponse]:
async def pages(self) -> AsyncIterator[logging_config.ListExclusionsResponse]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = await self._method(self._request, metadata=self._metadata)
yield self._response

def __aiter__(self) -> AsyncIterable[logging_config.LogExclusion]:
def __aiter__(self) -> AsyncIterator[logging_config.LogExclusion]:
async def async_generator():
async for page in self.pages:
for response in page.exclusions:
Expand Down
Loading

0 comments on commit bba3eea

Please sign in to comment.