PaginatedFetcher now it a context manager#8
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request refactors the usage of the
PaginatedFetcherin several CLI commands to use a context manager (withstatement) instead of manual lifecycle management. This change ensures that resources are properly cleaned up and that thestop()method is always called when breaking out of paginated loops. Additionally, thePaginatedFetcherclass is updated to support the context manager protocol, and related tests are updated accordingly.PaginatedFetcher context manager integration:
Added
__enter__and__exit__methods toPaginatedFetcherinclient.py, allowing it to be used with awithstatement. The__exit__method ensuresstop()is called automatically when exiting the context, simplifying resource management for callers.Updated CLI commands in
file.py,images.py, andoperation.pyto usewith PaginatedFetcher(...) as fetcher:instead of manually creating the fetcher and callingstop(). This change removes the need for explicitfetcher.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:
test_small_limit_uses_capped_page_size_in_requesttest intest_client.pyto use the context manager pattern forPaginatedFetcher, reflecting the new recommended usage and ensuring proper cleanup in tests.