| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
There was a problem hiding this comment.
This looks good to me with one minor thing.
Sorry, something went wrong.
| """Get the next value in the iterator.""" | ||
| item = six.next(self._item_iter) | ||
| result = self._item_to_value(item) | ||
| result = self._parent._item_to_value(item) |
|
SGTM On Fri, Oct 14, 2016 at 2:40 PM Danny Hermes notifications@github.com
|
Sorry, something went wrong.
| [ | ||
| <MyItemClass at 0x7fea740abdd0>, | ||
| <MyItemClass at 0x7fea740abe50>, | ||
| ] |
| blob._set_properties(item) | ||
| return blob | ||
|
|
||
| def _update_page(self): |
The previous implementation may catch users off guard since the iterator.page access may also update the value before access. In addition, this PR removed the _update_page() / next_page() subclass behavior in _BlobIterator. Over-riding that method was never intended. Instead makes a non-public class attribute _PAGE_CLASS that can be replaced with Page subclasses. This can be revisited if more implementations require custom behavior on Page creation / Page.__init__.
| if self.has_next_page(): | ||
| response = self._get_next_page_response() | ||
| self._page = self.PAGE_CLASS(self, response) | ||
| if self._page is NO_MORE_PAGES: |
|
I'm pretty okay with the combination of page is None and not has_next_page() On Fri, Oct 14, 2016, 5:17 PM Danny Hermes notifications@github.com wrote:
|
Sorry, something went wrong.
|
Alternatively, why does iterator.next_page() return True for no results? |
Sorry, something went wrong.
Also renaming next_page() to update_page() on Iterator and dropping any return value from that method. Also throwing an AttributeError if the page is unset on @Property access.
This is because Iterator.page combined with Iterator.update_page() can provide the same thing and has_next_page() is really an implementation detail. Done via: $ git grep -l has_next_page | > xargs sed -i s/has_next_page/_has_next_page/g
|
@jonparrott PTAL. I did what we discussed out-of-band yesterday. Instead of using None for both unstarted and no more pages, I used a private sentinel for _UNSET page (will never come via the @property since it raises AttributeError). I also made _has_next_page() private in another commit since Iterator.page combined with Iterator.update_page() cover the same functionality without exposing the has_next_page() helper used in iteration. |
Sorry, something went wrong.
|
@dhermes, why the name change from next_page() to update_page()? |
Sorry, something went wrong.
|
@daspecster Because next_page() sounds like it will return a page, but the method is intended to update the local state |
Sorry, something went wrong.
|
@dhermes yeah I guess I was confused by this example https://github.com/GoogleCloudPlatform/google-cloud-python/pull/2545/files#diff-1e128fc6c096e8635aabf4ba0c484200R90. |
Sorry, something went wrong.
|
@daspecster Let's continue design discussion in #2548 |
Sorry, something went wrong.
Moving backend specific behavior from Page to Iterator.
| Back | FazBrowse Home | New Git URL |
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.