Skip to content

Commit 42a765e

Browse files
authored
Restore python type-only constructs for simplicity (#327)
1 parent 6a90835 commit 42a765e

File tree

10 files changed

+203
-198
lines changed

10 files changed

+203
-198
lines changed

obstore/python/obstore/__get.py

-114
This file was deleted.

obstore/python/obstore/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from typing import TYPE_CHECKING
22

3-
from .__get import GetOptions, OffsetRange, SuffixRange
4-
from .__put import PutMode, PutResult, UpdateVersion
5-
from .__sign import HTTP_METHOD
6-
from ._attributes import Attribute, Attributes
73
from ._obstore import *
84
from ._obstore import ___version
95

obstore/python/obstore/__put.py

-56
This file was deleted.

obstore/python/obstore/__sign.py

-14
This file was deleted.

obstore/python/obstore/_get.pyi

+109-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,119 @@
11
from collections.abc import Sequence
2+
from datetime import datetime
3+
from typing import TypedDict
24

3-
from .__get import GetOptions
45
from ._attributes import Attributes
56
from ._bytes import Bytes
67
from ._list import ObjectMeta
78
from .store import ObjectStore
89

10+
class OffsetRange(TypedDict):
11+
"""Request all bytes starting from a given byte offset."""
12+
13+
offset: int
14+
"""The byte offset for the offset range request."""
15+
16+
class SuffixRange(TypedDict):
17+
"""Request up to the last `n` bytes."""
18+
19+
suffix: int
20+
"""The number of bytes from the suffix to request."""
21+
22+
class GetOptions(TypedDict, total=False):
23+
"""Options for a get request.
24+
25+
All options are optional.
26+
"""
27+
28+
if_match: str | None
29+
"""
30+
Request will succeed if the `ObjectMeta::e_tag` matches
31+
otherwise returning [`PreconditionError`][obstore.exceptions.PreconditionError].
32+
33+
See <https://datatracker.ietf.org/doc/html/rfc9110#name-if-match>
34+
35+
Examples:
36+
37+
```text
38+
If-Match: "xyzzy"
39+
If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
40+
If-Match: *
41+
```
42+
"""
43+
44+
if_none_match: str | None
45+
"""
46+
Request will succeed if the `ObjectMeta::e_tag` does not match
47+
otherwise returning [`NotModifiedError`][obstore.exceptions.NotModifiedError].
48+
49+
See <https://datatracker.ietf.org/doc/html/rfc9110#section-13.1.2>
50+
51+
Examples:
52+
53+
```text
54+
If-None-Match: "xyzzy"
55+
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
56+
If-None-Match: *
57+
```
58+
"""
59+
60+
if_unmodified_since: datetime | None
61+
"""
62+
Request will succeed if the object has been modified since
63+
64+
<https://datatracker.ietf.org/doc/html/rfc9110#section-13.1.3>
65+
"""
66+
67+
if_modified_since: datetime | None
68+
"""
69+
Request will succeed if the object has not been modified since
70+
otherwise returning [`PreconditionError`][obstore.exceptions.PreconditionError].
71+
72+
Some stores, such as S3, will only return `NotModified` for exact
73+
timestamp matches, instead of for any timestamp greater than or equal.
74+
75+
<https://datatracker.ietf.org/doc/html/rfc9110#section-13.1.4>
76+
"""
77+
78+
range: tuple[int, int] | list[int] | OffsetRange | SuffixRange
79+
"""
80+
Request transfer of only the specified range of bytes
81+
otherwise returning [`NotModifiedError`][obstore.exceptions.NotModifiedError].
82+
83+
The semantics of this tuple are:
84+
85+
- `(int, int)`: Request a specific range of bytes `(start, end)`.
86+
87+
If the given range is zero-length or starts after the end of the object, an
88+
error will be returned. Additionally, if the range ends after the end of the
89+
object, the entire remainder of the object will be returned. Otherwise, the
90+
exact requested range will be returned.
91+
92+
The `end` offset is _exclusive_.
93+
94+
- `{"offset": int}`: Request all bytes starting from a given byte offset.
95+
96+
This is equivalent to `bytes={int}-` as an HTTP header.
97+
98+
- `{"suffix": int}`: Request the last `int` bytes. Note that here, `int` is _the
99+
size of the request_, not the byte offset. This is equivalent to `bytes=-{int}`
100+
as an HTTP header.
101+
102+
<https://datatracker.ietf.org/doc/html/rfc9110#name-range>
103+
"""
104+
105+
version: str | None
106+
"""
107+
Request a particular object version
108+
"""
109+
110+
head: bool
111+
"""
112+
Request transfer of no content
113+
114+
<https://datatracker.ietf.org/doc/html/rfc9110#name-head>
115+
"""
116+
9117
class GetResult:
10118
"""Result for a get request.
11119

obstore/python/obstore/_obstore.pyi

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from ._attributes import Attribute as Attribute
2+
from ._attributes import Attributes as Attributes
13
from ._buffered import AsyncReadableFile as AsyncReadableFile
24
from ._buffered import AsyncWritableFile as AsyncWritableFile
35
from ._buffered import ReadableFile as ReadableFile
@@ -12,7 +14,10 @@ from ._copy import copy_async as copy_async
1214
from ._delete import delete as delete
1315
from ._delete import delete_async as delete_async
1416
from ._get import BytesStream as BytesStream
17+
from ._get import GetOptions as GetOptions
1518
from ._get import GetResult as GetResult
19+
from ._get import OffsetRange as OffsetRange
20+
from ._get import SuffixRange as SuffixRange
1621
from ._get import get as get
1722
from ._get import get_async as get_async
1823
from ._get import get_range as get_range
@@ -28,10 +33,14 @@ from ._list import ObjectMeta as ObjectMeta
2833
from ._list import list as list # noqa: A004
2934
from ._list import list_with_delimiter as list_with_delimiter
3035
from ._list import list_with_delimiter_async as list_with_delimiter_async
36+
from ._put import PutMode as PutMode
37+
from ._put import PutResult as PutResult
38+
from ._put import UpdateVersion as UpdateVersion
3139
from ._put import put as put
3240
from ._put import put_async as put_async
3341
from ._rename import rename as rename
3442
from ._rename import rename_async as rename_async
43+
from ._sign import HTTP_METHOD as HTTP_METHOD
3544
from ._sign import SignCapableStore as SignCapableStore
3645
from ._sign import sign as sign
3746
from ._sign import sign_async as sign_async

0 commit comments

Comments
 (0)