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 — fix: improper types in pagers generation by dpcollins-google · Pull Request #970 · googleapis/gapic-generator-python

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

Conversation

@dpcollins-google

@dpcollins-google dpcollins-google commented Aug 16, 2021

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

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

All reactions
@dpcollins-google
fix: improper types in pagers generation
36098c7
Generators are Iterators not Iterables https://docs.python.org/3/library/typing.html#typing.Generator
@dpcollins-google
dpcollins-google requested a review from a team August 16, 2021 15:32
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 16, 2021
@busunkim96
busunkim96 requested a review from software-dov August 16, 2021 15:46
tseaver
tseaver approved these changes Aug 16, 2021
View reviewed changes

@tseaver tseaver 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.

The change is correct, if a bit nit-picky (Iterable is a less restrictive contract than Iterator, and a strict superset). Do we have cases where type-checking actually complains about the difference? I guess that would be clients calling next(thing) directly?

Sorry, something went wrong.

Uh oh!

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

All reactions
@dpcollins-google dpcollins-google mentioned this pull request Aug 16, 2021
fix: Enable pytype on Pub/Sub Lite repo and fix all errors googleapis/python-pubsublite#214
Merged
@dpcollins-google

dpcollins-google commented Aug 16, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

The change is correct, if a bit nit-picky (Iterable is a less restrictive contract than Iterator, and a strict superset). Do we have cases where type-checking actually complains about the difference? I guess that would be clients calling next(thing) directly?

This is not quite correct. Iterables are not required to have __next__ methods, they only usually do :) https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable

In fact, you can see this with <*>Pager itself: it is an Iterable (with __iter__) but not an Iterator (no __next__)

All reactions

Sorry, something went wrong.

Uh oh!

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

@busunkim96

busunkim96 commented Aug 16, 2021

Copy link
Copy Markdown
Contributor

@dpcollins-google could you update the golden files? That should resolve the one failing Tests / integration check. See instructions here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tseaver

tseaver commented Aug 16, 2021

Copy link
Copy Markdown
Contributor

@dpcollins-google I think we are in violent agreement here: Iterable requires only __iter__, while Iterator must also have __next__ which is a) more restrictive than Iterable, and b) makes the contract for Iterator a "sub-type" of Iterable (no types which implement Iterator do not also implement Iterable).

At any rate, my question remains: do we have reported errors from pytype in this repo, or even in the wild, where declaring the less-restrictive type (Iterable) is causing errors? My surmise is that either in this repo or elsewhere, somebody is using next(response), rather than for foo in response:.

All reactions

Sorry, something went wrong.

Uh oh!

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

busunkim96 and others added 2 commits September 28, 2021 23:06
@busunkim96
chore: update goldens
3980ee2
@busunkim96
Merge branch 'master' into patch-3
9618566
@busunkim96

busunkim96 commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

It looks like this is causing a problem for Pub/Sub (see log, so I'm inclined to merge it now and re-visit if it causes an issue.

@software-dov @atulep Could you also take a look as the generator owners?

All reactions

Sorry, something went wrong.

Uh oh!

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

@dpcollins-google

dpcollins-google commented Sep 29, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

To clarify, the issue this is causing is that PyType detects that its wrong: the pager object itself is NOT an Iterator because its __iter__ method doesn't return an Iterator, it returns an Iterable, which doesn't have a __next__ method defined.

All reactions

Sorry, something went wrong.

Uh oh!

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

@atulep

atulep commented Sep 29, 2021

Copy link
Copy Markdown
Contributor

From https://docs.python.org/3/library/typing.html#typing.Generator, generator can have a return type of either Iterable or Iterator. Why is this change needed?

Does Pub/Sub fail because a caller of the pager expects an iterator instead of iterable?

All reactions

Sorry, something went wrong.

Uh oh!

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

@dpcollins-google

dpcollins-google commented Sep 29, 2021

Copy link
Copy Markdown
Contributor Author

Please see my comment above. The Pager itself does not model Iterable because its __iter__ method states incorrectly that it returns an Iterable when it needs to return an Iterator.

All reactions

Sorry, something went wrong.

Uh oh!

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

@atulep
atulep self-requested a review September 29, 2021 19:00
atulep
atulep approved these changes Sep 29, 2021
View reviewed changes
@busunkim96
busunkim96 merged commit bba3eea into googleapis:master Sep 29, 2021
gcf-merge-on-green Bot pushed a commit that referenced this pull request Sep 29, 2021
@release-please
chore: release 0.52.0 (#995)
0c40194
🤖 I have created a release \*beep\* \*boop\*
---
## [0.52.0](https://www.github.com/googleapis/gapic-generator-python/compare/v0.51.2...v0.52.0) (2021-09-29)


### Features

* Support alternative http bindings in the gapic schema. ([#993](https://www.github.com/googleapis/gapic-generator-python/issues/993)) ([041a726](https://www.github.com/googleapis/gapic-generator-python/commit/041a726b818cd67812d689c23757f31ec9964d66))


### Bug Fixes

* improper types in pagers generation ([#970](https://www.github.com/googleapis/gapic-generator-python/issues/970)) ([bba3eea](https://www.github.com/googleapis/gapic-generator-python/commit/bba3eea5d45fe57c0395ceef30402ad7880013d7))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@busunkim96 busunkim96 mentioned this pull request Oct 12, 2021
mypy type error for pager #991
Closed
This was referenced Jan 18, 2022
chore(master): release reverted #1133
Merged
chore(master): release 0.40.0 #1138
Closed
chore(master): release 0.39.1 #1146
Closed
This was referenced Jan 26, 2022
chore(main): release 0.39.1 #1160
Closed
chore(main): release 0.39.1 #1162
Closed
chore(main): release 0.61.0 #1163
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@software-dov software-dov Awaiting requested review from software-dov
2 more reviewers
@tseaver tseaver tseaver approved these changes
@atulep atulep atulep 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

@dpcollins-google @busunkim96 @tseaver @atulep
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.