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

Add __len__ to ItemPaged class #9970

Closed
akshaybabloo opened this issue Feb 23, 2020 · 5 comments
Closed

Add __len__ to ItemPaged class #9970

akshaybabloo opened this issue Feb 23, 2020 · 5 comments
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Milestone

Comments

@akshaybabloo
Copy link

Is your feature request related to a problem? Please describe.
For the class ItemPaged at

class ItemPaged(Iterator[ReturnType]):

It would be nice to add __len__ function.

Describe the solution you'd like

Because it's an iterator using len() on it will give TypeError: object of type 'ItemPaged' has no len(). Yes you can use len(list()), but it's too wordy.

@kaerm kaerm added Azure.Core Client This issue points to a problem in the data-plane of the library. labels Feb 23, 2020
@kaerm
Copy link
Contributor

kaerm commented Feb 23, 2020

@akshaybabloo thanks for the feedback! Someone from our team will take a look into this //cc: @lmazuel

@lmazuel
Copy link
Member

lmazuel commented Mar 9, 2020

@akshaybabloo the problem here is that we don't necessarly know in advance the length of this iterable. This is lazy loading, as you move around the iterator.
https://docs.python.org/3.8/library/collections.abc.html?highlight=abc

as you can see an iterator has no len

@xiangyan99 xiangyan99 added this to the [2020] April milestone Mar 11, 2020
@xiangyan99
Copy link
Member

Agree with Laurent. For paged item, we only know the length of this page which is not the real length of the operation. Close as by design but feel free to reopen it if you have concern.

@mcapuccini
Copy link

This is such a basic requirement, couldn't you add a count function? There are a lot of lazily loaded collections that do this.

@josiahdc
Copy link

ditto to the above, len is such a fundamental attribute of any collection

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

No branches or pull requests

6 participants