Skip to content

sandbox: Add current-page iteration to pages#79

Draft
scotttrinh wants to merge 1 commit intomainfrom
add-page-iterator
Draft

sandbox: Add current-page iteration to pages#79
scotttrinh wants to merge 1 commit intomainfrom
add-page-iterator

Conversation

@scotttrinh
Copy link
Copy Markdown
Collaborator

Add direct iteration support to sandbox and snapshot page objects. This iterates only the items already loaded on that page. Leave iter_items() behavior unchanged for now so cross-page iteration still uses the existing explicit API.

Add direct iteration support to sandbox and snapshot page objects. This
iterates only the items already loaded on that page. Leave iter_items()
behavior unchanged for now so cross-page iteration still uses the
existing explicit API.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vercel-py Ready Ready Preview Mar 31, 2026 3:01pm

Request Review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds direct iteration support to sandbox/snapshot page objects so callers can iterate over only the items already loaded in the current page, while leaving cross-page iteration behavior on iter_items() unchanged.

Changes:

  • Implement __iter__ / __aiter__ on SandboxPage/AsyncSandboxPage and SnapshotPage/AsyncSnapshotPage to iterate only the current page’s items.
  • Extend unit tests to assert the new direct-iteration behavior for snapshot pages.
  • Update the sandbox listing example to demonstrate direct iteration over the first async page.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/vercel/sandbox/page.py Adds direct iteration methods on page objects (sync + async) that yield only currently-loaded items.
tests/unit/test_sandbox_page.py Adds assertions verifying direct iteration for snapshot page types (sync + async).
examples/sandbox_15_list.py Demonstrates iterating items directly from the first async page before using pager-wide iteration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +61 to +63
def __iter__(self) -> Iterator[SandboxModel]:
return iter(self.sandboxes)

Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct iteration was added for SandboxPage/AsyncSandboxPage here, but the PR’s tests only assert this behavior for SnapshotPage/AsyncSnapshotPage. Please add coverage that iterating a sandbox page (for sandbox in page / async for sandbox in page) yields only the already-loaded items and does not fetch subsequent pages (to guard against future regressions and to match the PR’s stated semantics).

Copilot uses AI. Check for mistakes.
return self._controller.iter_items_sync(self)

def __iter__(self) -> Iterator[SandboxModel]:
return iter(self.sandboxes)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. iter_items supposed to do the same that __iter__ you add but implementation is different? Why?

Also can we drop iter_items()? The name is very bad, in Python std lib it's reserved for iterating over key/values, here we're iterating over just values. This is bad api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants