8000 Add comments to clarify queryset iteration by jorwoods · Pull Request #1004 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Add comments to clarify queryset iteration #1004

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

Merged
merged 1 commit into from
Mar 18, 2022

Conversation

jorwoods
Copy link
Contributor

@jacalata Hope that is clearer.

@@ -31,12 +35,16 @@ def __getitem__(self, k):
page = self.page_number
size = self.page_size

# Create a range object for quick checking if k is in the cached result.
page_range = range((page - 1) * size, page * size)

if isinstance(k, slice):
Copy link
Contributor

Choose a reason for hiding this comment

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

is slice ever set here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k can either be an int or a slice object.

It could be a slice if it was called in the following manner:

server.workbooks.all()[10:40:3]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that example, if the client code calls

server.workbooks.all()[10:40:3]

Then __getitem__ receives k=slice(start=10, stop=40, step=3). Any of the typical slicing syntax will work. For server.workbooks.all()[:50] then k=slice(start=None, stop=50, step=None), then the None's get replaced with sensible defaults so that it acts the way that slicing would on a list.

If start is None, it becomes 0
If stop is None, it becomes the total number available
If step is None, it becomes 1

@jacalata jacalata merged commit a3bf3e8 into tableau:development Mar 18, 2022
@jorwoods jorwoods deleted the jorwoods/queryset_comments branch March 25, 2022 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0