Skip to content

PaginatedFetcher now it a context manager#8

Merged
mosquito merged 1 commit into
masterfrom
feature/cm-for-pager
May 19, 2026
Merged

PaginatedFetcher now it a context manager#8
mosquito merged 1 commit into
masterfrom
feature/cm-for-pager

Conversation

@mosquito
Copy link
Copy Markdown
Collaborator

This pull request refactors the usage of the PaginatedFetcher in several CLI commands to use a context manager (with statement) instead of manual lifecycle management. This change ensures that resources are properly cleaned up and that the stop() method is always called when breaking out of paginated loops. Additionally, the PaginatedFetcher class is updated to support the context manager protocol, and related tests are updated accordingly.

PaginatedFetcher context manager integration:

  • Added __enter__ and __exit__ methods to PaginatedFetcher in client.py, allowing it to be used with a with statement. The __exit__ method ensures stop() is called automatically when exiting the context, simplifying resource management for callers.

  • Updated CLI commands in file.py, images.py, and operation.py to use with PaginatedFetcher(...) as fetcher: instead of manually creating the fetcher and calling stop(). This change removes the need for explicit fetcher.stop() calls after breaking out of loops. [1] [2] [3]

  • Removed redundant or now-unnecessary calls to fetcher.stop() after breaking from paginated loops in the CLI command implementations. [1] [2] [3]

Test updates:

  • Updated the test_small_limit_uses_capped_page_size_in_request test in test_client.py to use the context manager pattern for PaginatedFetcher, reflecting the new recommended usage and ensuring proper cleanup in tests.

@mosquito mosquito requested a review from insomnes May 19, 2026 14:36
Copy link
Copy Markdown
Collaborator

@insomnes insomnes left a comment

Choose a reason for hiding this comment

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

LGTM

@mosquito mosquito merged commit f68199f into master May 19, 2026
19 checks passed
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.

2 participants