Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-733: Refactor Token Paginator #47

Conversation

asein-sinch
Copy link
Contributor

@matsk-sinch : Proposal to simplify the implementation and usage of the token paginator


list_response = token_based_paginator.get_content()
active_numbers_list = [num.phone_number for num in token_based_paginator.iterator()]
Copy link
Contributor

Choose a reason for hiding this comment

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

The TokenBasedPaginator is a custom iterator that lazily retrieves one item at a time. However, when wrapped with list() or [ ], Python fully consumes the iterator, loading all items into memory at once ⚠️.

To prevent excessive memory usage, you should use lazy iteration with while or for loops instead.

While the current tests handle small data, this practice should be avoided in real-world scenarios. Proper examples and a quickstart guide will be provided soon. However, users exploring the unit tests for reference should not be encouraged to use list().

async for _ in async_token_based_paginator.iterator():
number_counter += 1
active_numbers_list = [
num.phone_number async for num in async_token_based_paginator.iterator()
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

"PagedResponse", ["result", "has_next_page", "next_page_info", "next_page"]
)

next_page_info = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we keep this info?

@asein-sinch
Copy link
Contributor Author

Information reported in the initial PR by @matsk-sinch . Closing this one

@asein-sinch asein-sinch deleted the DEVEXP-733_Refactor-Token-Paginator branch February 25, 2025 08:36
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