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 — Re-architect Iterator class. by dhermes · Pull Request #2531 · googleapis/google-cloud-python

Conversation

@dhermes

@dhermes dhermes commented Oct 12, 2016

Copy link
Copy Markdown
Contributor

This PR should definitely reviewed commit-by-commit.

Primary changes are:

  • Have an iterable Page base-class for iterating over a single page of a result set
  • Move most custom iterator logic back up into the base page and iterator classes

Sorry, something went wrong.

Uh oh!

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

All reactions
@dhermes dhermes added api: storage Issues related to the Cloud Storage API. api: core api: cloudresourcemanager Issues related to the Resource Manager API. labels Oct 12, 2016
@dhermes dhermes assigned daspecster and tseaver Oct 12, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 12, 2016
dhermes added 13 commits October 12, 2016 01:05
@dhermes
Implementing basic Page class to help with Iterator.
6636714
Intended to hold and slice up state that has already been
retrieved from the server.
@dhermes
Collapsing get_items_from_response behavior into Page subclasses.
e9d600a
@dhermes
Collapsing Page __init__ functionality into base class.
819e644
@dhermes
Replacing get_items_from_response() with a page class.
afc0662
@dhermes
Making path an optional argument to Iterator.
ff85b24
@dhermes
Swapping iterator's _next_item() for _item_to_value().
5326c88
This is so that the owned items iterator management could
be done on the base class and the child classes just
need to worry about converting the JSON values to whatever
type is required.
@dhermes
Exposing the current page in iterator.
f4c2bcd
@dhermes
Removing RuntimeError from iterator's get_next_page_response().
4988a2a
This state can never happen since a StopIteration will occur
before the method would ever be called without a token.
@dhermes
Adding a page reset to iterator's reset.
736c3a0
Also doing a tiny re-org in constructor to separate the
attributes which change and those which don't.
@dhermes
Updating storage system test after Iterator refactor.
122ec89
@dhermes
Lint cleanup: unused imports.
c6218a2
@dhermes
Removing unused MethodIterator.
c92961d
@dhermes
Implementation hiding in Iterator class.
d9824c6
Making JSON API call helpers non-public. This reduces the
interface to methods relevant to iterating.
@dhermes
dhermes force-pushed the revamp-iterator branch from 6d50cf6 to d9824c6 Compare October 12, 2016 08:07
@dhermes dhermes mentioned this pull request Oct 12, 2016
Moving to iterators in DNS. #2532
Closed
theacodes
theacodes reviewed Oct 14, 2016
View reviewed changes

@theacodes theacodes left a comment •
edited
Loading

Uh oh!

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

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.

My one concern is how a service like datastore will work.

This abstraction seems to completely hides cursors, but cursors often need to be passed between client and server in datastore (think client-side pagination). I'm wondering how that would fit in here?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread core/google/cloud/iterator.py
"""The :class:`Page` is an iterator."""
return self

def _item_to_value(self, item):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

Comment thread core/google/cloud/iterator.py
return self._num_items

@property
def remaining(self):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Oct 14, 2016

Copy link
Copy Markdown
Contributor Author

My one concern is how a service like datastore will work.

Datastore has it's own specialized Iterator. For the time being, the google.cloud.iterator.Iterator class is for JSON-based APIs that define a nextPageToken in response pages.

Though a "next step" would be to make the iterator support gRPC / GAPIC generated classes, so we may be able to tackle datastore there. (Just not in this PR.)

All reactions

Sorry, something went wrong.

Uh oh!

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

@daspecster

daspecster commented Oct 14, 2016

Copy link
Copy Markdown
Contributor

Sorry I haven't responded on this @dhermes. I don't have much feedback though.

You actually just answered the question I did have.

Though a "next step" would be to make the iterator support gRPC / GAPIC generated classes, so we may be able to tackle datastore there. (Just not in this PR.)

All reactions

Sorry, something went wrong.

Uh oh!

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

@theacodes

theacodes commented Oct 14, 2016

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes
dhermes merged commit 9a5ddd5 into googleapis:master Oct 14, 2016
@dhermes
dhermes deleted the revamp-iterator branch October 14, 2016 19:09
dhermes added a commit to dhermes/google-cloud-python that referenced this pull request Oct 14, 2016
@dhermes
Moving backend specific behavior from Page to Iterator.
49532f4
This is to lower the burden on implementers. The previous
approach (requiring a Page and Iterator subclass) ended
up causing lots of copy-pasta docstrings that were just
a distraction.

Follow up to googleapis#2531.
@dhermes dhermes mentioned this pull request Oct 14, 2016
Moving backend specific behavior from Page to Iterator. #2545
Merged
@dhermes dhermes mentioned this pull request Nov 14, 2016
Upgrading core to version to 0.21.0. #2733
Merged
@dhermes dhermes mentioned this pull request Dec 9, 2016
Update versions for mega-release. #2846
Merged
@tseaver tseaver mentioned this pull request Feb 6, 2017
Update iterator to take a method and **kwargs #1554
Closed
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
@dhermes
Merge pull request googleapis#2531 from dhermes/revamp-iterator
ba13299
Re-architect Iterator class.
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
@dhermes
Moving backend specific behavior from Page to Iterator.
9c1a083
This is to lower the burden on implementers. The previous
approach (requiring a Page and Iterator subclass) ended
up causing lots of copy-pasta docstrings that were just
a distraction.

Follow up to googleapis#2531.
@theacodes theacodes unassigned daspecster Sep 28, 2018
parthea pushed a commit that referenced this pull request Jun 4, 2023
@dhermes
Moving backend specific behavior from Page to Iterator.
ab05218
This is to lower the burden on implementers. The previous
approach (requiring a Page and Iterator subclass) ended
up causing lots of copy-pasta docstrings that were just
a distraction.

Follow up to #2531.
parthea pushed a commit that referenced this pull request Nov 24, 2025
@dhermes
Merge pull request #2531 from dhermes/revamp-iterator
3c879aa
Re-architect Iterator class.
parthea pushed a commit that referenced this pull request Nov 24, 2025
@dhermes
Moving backend specific behavior from Page to Iterator.
9e2fbee
This is to lower the burden on implementers. The previous
approach (requiring a Page and Iterator subclass) ended
up causing lots of copy-pasta docstrings that were just
a distraction.

Follow up to #2531.
parthea pushed a commit that referenced this pull request Mar 9, 2026
@dhermes
Moving backend specific behavior from Page to Iterator.
1ab8a98
This is to lower the burden on implementers. The previous
approach (requiring a Page and Iterator subclass) ended
up causing lots of copy-pasta docstrings that were just
a distraction.

Follow up to #2531.
ohmayr added a commit that referenced this pull request Mar 13, 2026
@ohmayr
chore: cache proto context to optimize generator performance (#2531)
35d1b0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@theacodes theacodes theacodes left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@tseaver tseaver

Labels

api: cloudresourcemanager Issues related to the Resource Manager API. api: core api: storage Issues related to the Cloud Storage API. 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.

5 participants

@dhermes @daspecster @theacodes @tseaver @googlebot
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.