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

mypy type error for pager #991

Closed
tmshn opened this issue May 28, 2021 · 3 comments
Closed

mypy type error for pager #991

tmshn opened this issue May 28, 2021 · 3 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tmshn
Copy link

tmshn commented May 28, 2021

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS type and version: macOS/debian
  • Python version: python --version 3.9.1
  • pip version: pip --version 21.0.1
  • google-cloud-datacatalog version: pip show google-cloud-datacatalog 3.2.0
  • mypy version: 0.812

Steps to reproduce

  1. use DataCatlogClient#list_tags in for-loop
  2. check that code using mypy

Code example

from google.cloud import datacatalog

dcclient = datacatalog.DataCatalogClient()
for tag in dcclient.list_tags(parent="dummy"):
    print(tag)

Error

$ mypy snippet.py
snippet.py:4:12: error: "Iterable[Tag]" has no attribute "__next__"
Found 1 error in 1 file (checked 1 source file)

I suspect this is due to the return type of ListTagsPager#__iter__ is annotated as Iterable rather than Iterator, but not sure (according to the Python protocol, Iterable only offers __iter__ method, while Iterator offers __next__).

https://github.com/googleapis/python-datacatalog/blob/936800c92a348b8ce438c4b608f17fe6d9f926a1/google/cloud/datacatalog_v1beta1/services/data_catalog/pagers.py#L470

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

@tswast
Copy link

tswast commented Sep 13, 2021

This is generated code. Moving to generator component.

@tswast tswast transferred this issue from googleapis/python-datacatalog Sep 13, 2021
@busunkim96
Copy link
Contributor

@dpcollins-google ran into the same issue for Pub/Sub (see #970) and opened a bug fix to switch the annotation to Iterator.

The main branch for datacatalog pages now has the correct annotation and was released last week in google-cloud-datalog==3.4.3. https://github.com/googleapis/python-datacatalog/blob/main/CHANGELOG.md#343-2021-10-05

https://github.com/googleapis/python-datacatalog/blob/16435a3753d760cec3d88a025630d109cbe52310/google/cloud/datacatalog_v1beta1/services/data_catalog/pagers.py#L463-L472

    @property
    def pages(self) -> Iterator[datacatalog.ListTagsResponse]:
        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) -> Iterator[tags.Tag]:
        for page in self.pages:
            yield from page.tags

Closing this issue as I believe it has been resolved, but please let me know if you are still seeing issues @tmshn.

@software-dov software-dov added priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 27, 2021
@vam-google vam-google added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 27, 2021
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Apr 25, 2022
@parthea parthea closed this as completed Feb 16, 2023
@parthea
Copy link
Contributor

parthea commented Feb 16, 2023

Closing as obsolete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

7 participants