Add ArrayResponse and use it for GroupsClient.get_my_groups #575
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.
I noticed some code out in the wild doing
Naturally, we'd like to be able to write this inline as
but the response object is not iterable.
The overall goal of this PR is to enable the above style of usage by adding
response.ArrayResponse
and using that inGroupsClient.get_my_groups
.ArrayResponse
should support__iter__
and__getitem__
at least, arguably__len__
as well.Along the way, I've checked for dunder methods other than
__iter__
which are missing and which make sense to implement on the ArrayResponse type. Some interesting things:__bool__
is reasonable in the normal cases, and even makes sense on dict data. You could take a very strict line and consider its introduction breaking because previouslybool(response)
was alwaysTrue
. I think that's far too strict, and have included__bool__
__getitem__
needs changes. At first, I thoughtArrayResponse.__getitem__
would be specialized, but the base response class doesn't claim to not handle arrays. So__getitem__
now acceptsstr | int | slice
in its annotation.__len__
looks like it would work on the base response class, but it has some corner-case behaviors which would likely prove confusing.len(IterableResponse(...))
andlen(response)
whenresponse.data is None
are two of the more noteworthy. The first commit in this series defined__len__
onGlobusHTTPResponse
, but it has been narrowed to onlyArrayResponse
.__contains__
,get()
and other methods were untested