1
- # ruff: noqa: UP006
2
- # ruff: noqa: UP035
3
- # Use `list` instead of `List` for type annotation
4
- # `typing.List` is deprecated, use `list` instead
5
- # ruff: noqa: A001
6
- # Variable `list` is shadowing a Python builtinRuff
1
+ # ruff: noqa: A001, UP006, UP035
7
2
8
- from typing import Generic , List , Literal , Self , TypedDict , TypeVar , overload
3
+ from typing import List , Literal , overload
9
4
10
5
from arro3 .core import RecordBatch , Table
6
+ from obspec ._list import ListResult , ListStream
11
7
from obspec ._meta import ObjectMeta
12
8
13
- from .store import ObjectStore
14
-
15
- ListChunkType = TypeVar ("ListChunkType" , List [ObjectMeta ], RecordBatch , Table ) # noqa: PYI001
16
- """The data structure used for holding list results.
17
-
18
- By default, listing APIs return a `list` of [`ObjectMeta`][obspec.ObjectMeta]. However
19
- for improved performance when listing large buckets, you can pass `return_arrow=True`.
20
- Then an Arrow `RecordBatch` will be returned instead.
21
-
22
- This implements [`obspec.ListChunkType_co`][], but is redefined here to specialize the
23
- exact instance of the Arrow return type, given that in the obstore implementation, an
24
- [`arro3.core.RecordBatch`][] or [`arro3.core.Table`][] will always be returned.
25
- """
26
-
27
- class ListResult (TypedDict , Generic [ListChunkType ]):
28
- """Result of a list call.
29
-
30
- Includes objects, prefixes (directories) and a token for the next set of results.
31
- Individual result sets may be limited to 1,000 objects based on the underlying
32
- object storage's limitations.
33
-
34
- This implements [`obspec.ListResult`][].
35
- """
36
-
37
- common_prefixes : List [str ]
38
- """Prefixes that are common (like directories)"""
39
-
40
- objects : ListChunkType
41
- """Object metadata for the listing"""
42
-
43
- class ListStream (Generic [ListChunkType ]):
44
- """A stream of [ObjectMeta][obspec.ObjectMeta] that can be polled in a sync or
45
- async fashion.
46
-
47
- This implements [`obspec.ListStream`][].
48
- """ # noqa: D205
49
-
50
- def __aiter__ (self ) -> Self :
51
- """Return `Self` as an async iterator."""
52
-
53
- def __iter__ (self ) -> Self :
54
- """Return `Self` as an async iterator."""
55
-
56
- async def collect_async (self ) -> ListChunkType :
57
- """Collect all remaining ObjectMeta objects in the stream.
58
-
59
- This ignores the `chunk_size` parameter from the `list` call and collects all
60
- remaining data into a single chunk.
61
- """
62
-
63
- def collect (self ) -> ListChunkType :
64
- """Collect all remaining ObjectMeta objects in the stream.
65
-
66
- This ignores the `chunk_size` parameter from the `list` call and collects all
67
- remaining data into a single chunk.
68
- """
69
-
70
- async def __anext__ (self ) -> ListChunkType :
71
- """Return the next chunk of ObjectMeta in the stream."""
72
-
73
- def __next__ (self ) -> ListChunkType :
74
- """Return the next chunk of ObjectMeta in the stream."""
9
+ from ._store import ObjectStore
75
10
76
11
@overload
77
12
def list (
@@ -163,7 +98,7 @@ def list(
163
98
!!! note
164
99
There is no async version of this method, because `list` is not async under the
165
100
hood, rather it only instantiates a stream, which can be polled in synchronous
166
- or asynchronous fashion. See [`ListStream`][obstore .ListStream].
101
+ or asynchronous fashion. See [`ListStream`][obspec .ListStream].
167
102
168
103
Args:
169
104
store: The ObjectStore instance to use.
@@ -174,8 +109,8 @@ def list(
174
109
chunk_size: The number of items to collect per chunk in the returned
175
110
(async) iterator. All chunks except for the last one will have this many
176
111
items. This is ignored in the
177
- [`collect`][obstore .ListStream.collect] and
178
- [`collect_async`][obstore .ListStream.collect_async] methods of
112
+ [`collect`][obspec .ListStream.collect] and
113
+ [`collect_async`][obspec .ListStream.collect_async] methods of
179
114
`ListStream`.
180
115
return_arrow: If `True`, return each batch of list items as an Arrow
181
116
`RecordBatch`, not as a list of Python `dict`s. Arrow removes serialization
0 commit comments