Skip to content

Commit 1dbb759

Browse files
authored
feat(bindings/python): Add stubs for some more types (#6703)
* Stubs for Layers * Stubs for Metadata, Entry, and EntryMode * Add to API Reference
1 parent 9b11e7f commit 1dbb759

File tree

12 files changed

+568
-135
lines changed

12 files changed

+568
-135
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
::: opendal.Metadata
1+
::: opendal.Capability
22
options:
3-
heading: "opendal.Metadata"
3+
heading: "opendal.Capability"
44
heading_level: 2
55
show_source: false
66
show_bases: false
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
This page documents all exceptions raised by the OpenDAL.
2+
3+
::: opendal.exceptions.Error
4+
options:
5+
heading_level: 2
6+
7+
::: opendal.exceptions.AlreadyExists
8+
options:
9+
heading_level: 2
10+
11+
::: opendal.exceptions.ConditionNotMatch
12+
options:
13+
heading_level: 2
14+
15+
::: opendal.exceptions.ConfigInvalid
16+
options:
17+
heading_level: 2
18+
19+
::: opendal.exceptions.IsADirectory
20+
options:
21+
heading_level: 2
22+
23+
::: opendal.exceptions.IsSameFile
24+
options:
25+
heading_level: 2
26+
27+
::: opendal.exceptions.NotADirectory
28+
options:
29+
heading_level: 2
30+
31+
::: opendal.exceptions.NotFound
32+
options:
33+
heading_level: 2
34+
35+
::: opendal.exceptions.PermissionDenied
36+
options:
37+
heading_level: 2
38+
39+
::: opendal.exceptions.Unexpected
40+
options:
41+
heading_level: 2
42+
43+
::: opendal.exceptions.Unsupported
44+
options:
45+
heading_level: 2

bindings/python/docs/api/layers.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Layers
2+
3+
This page documents all layers in OpenDAL.
4+
5+
## Layer
6+
::: opendal.layers.Layer
7+
options:
8+
heading: "opendal.layers.Layer"
9+
heading_level: 2
10+
show_source: false
11+
show_bases: false
12+
13+
## RetryLayer
14+
::: opendal.layers.RetryLayer
15+
options:
16+
heading: "opendal.layers.RetryLayer"
17+
heading_level: 2
18+
show_source: false
19+
20+
## ConcurrentLimitLayer
21+
::: opendal.layers.ConcurrentLimitLayer
22+
options:
23+
heading: "opendal.layers.ConcurrentLimitLayer"
24+
heading_level: 2
25+
show_source: false
26+
27+
## MimeGuessLayer
28+
::: opendal.layers.MimeGuessLayer
29+
options:
30+
heading: "opendal.layers.MimeGuessLayer"
31+
heading_level: 2
32+
show_source: false

bindings/python/docs/api/types.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Types
2+
3+
This page documents all types in OpenDAL.
4+
5+
## Entry
6+
::: opendal.Entry
7+
options:
8+
heading: "opendal.Entry"
9+
heading_level: 2
10+
show_source: false
11+
show_bases: false
12+
13+
## EntryMode
14+
::: opendal.types.EntryMode
15+
options:
16+
heading: "opendal.EntryMode"
17+
heading_level: 2
18+
19+
## Metadata
20+
::: opendal.types.Metadata
21+
options:
22+
heading: "opendal.Metadata"
23+
heading_level: 2
24+
show_source: false
25+
show_bases: false

bindings/python/mkdocs.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ nav:
4343
- Pandas: examples/pandas.ipynb
4444
- Polars: examples/polars.ipynb
4545
- API Reference:
46-
- api/operator.md
47-
- api/file.md
48-
- api/async_operator.md
49-
- api/async_file.md
50-
- api/metadata.md
46+
- AsyncFile: api/async_file.md
47+
- AsyncOperator: api/async_operator.md
48+
- Capability: api/capability.md
49+
- Exceptions: api/exceptions.md
50+
- File: api/file.md
51+
- Layers: api/layers.md
52+
- Operator: api/operator.md
53+
- Types: api/types.md
5154

5255
markdown_extensions:
5356
- pymdownx.highlight:

bindings/python/pyrightconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"include": ["python/opendal/"],
3+
"ignore": [
4+
"python/opendal/*.pyi"
5+
]
6+
}

bindings/python/python/opendal/__init__.pyi

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import os
1919
from collections.abc import AsyncIterable, Iterable
20-
from datetime import datetime
2120
from types import TracebackType
2221
from typing import TypeAlias, final
2322

@@ -30,6 +29,7 @@ from opendal import layers as layers
3029
from opendal.__base import _Base
3130
from opendal.capability import Capability
3231
from opendal.layers import Layer
32+
from opendal.types import Entry, Metadata
3333

3434
PathBuf: TypeAlias = str | os.PathLike
3535

@@ -703,61 +703,6 @@ class AsyncFile:
703703
async def writable(self) -> bool:
704704
"""Check if the file is writable."""
705705

706-
@final
707-
class Entry:
708-
"""An entry in the directory listing."""
709-
710-
@property
711-
def path(self) -> str:
712-
"""The path of the entry."""
713-
@property
714-
def metadata(self) -> Metadata:
715-
"""The metadata of the entry."""
716-
717-
@final
718-
class Metadata:
719-
@property
720-
def content_disposition(self) -> str | None:
721-
"""The content disposition of the object."""
722-
@property
723-
def content_length(self) -> int:
724-
"""The content length of the object."""
725-
@property
726-
def content_md5(self) -> str | None:
727-
"""The MD5 checksum of the object."""
728-
@property
729-
def content_type(self) -> str | None:
730-
"""The mime type of the object."""
731-
@property
732-
def content_encoding(self) -> str | None:
733-
"""The content encoding of the object."""
734-
@property
735-
def etag(self) -> str | None:
736-
"""The ETag of the object."""
737-
@property
738-
def mode(self) -> EntryMode:
739-
"""The mode of the object."""
740-
@property
741-
def is_file(self) -> bool:
742-
"""Returns `True` if this metadata is for a file."""
743-
@property
744-
def is_dir(self) -> bool:
745-
"""Returns `True` if this metadata is for a directory."""
746-
@property
747-
def last_modified(self) -> datetime | None:
748-
"""The last modified time of the object."""
749-
@property
750-
def version(self) -> str | None:
751-
"""The version of the object, if available."""
752-
@property
753-
def user_metadata(self) -> str | None:
754-
"""The user defined metadata of the object."""
755-
756-
@final
757-
class EntryMode:
758-
def is_file(self) -> bool: ...
759-
def is_dir(self) -> bool: ...
760-
761706
@final
762707
class PresignedRequest:
763708
@property

bindings/python/python/opendal/layers.pyi

Lines changed: 114 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,122 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from typing import final
18+
# This file is automatically generated by pyo3_stub_gen
19+
# ruff: noqa: E501, F401
1920

20-
class Layer: ...
21+
import builtins
22+
import typing
2123

22-
@final
23-
class RetryLayer(Layer):
24-
def __init__(
25-
self,
26-
max_times: int | None = None,
27-
factor: float | None = None,
28-
jitter: bool = False,
29-
max_delay: float | None = None,
30-
min_delay: float | None = None,
31-
) -> None: ...
32-
33-
@final
24+
@typing.final
3425
class ConcurrentLimitLayer(Layer):
35-
def __init__(self, limit: int) -> None: ...
26+
r"""
27+
ConcurrentLimitLayer.
28+
29+
Create a layer that limits the number of concurrent operations.
30+
31+
Notes
32+
-----
33+
All operators wrapped by this layer will share a common semaphore. This
34+
allows you to reuse the same layer across multiple operators, ensuring
35+
that the total number of concurrent requests across the entire
36+
application does not exceed the limit.
37+
"""
38+
39+
def __new__(cls, limit: builtins.int) -> ConcurrentLimitLayer:
40+
r"""
41+
Create a new ConcurrentLimitLayer.
42+
43+
Parameters
44+
----------
45+
limit : int
46+
Maximum number of concurrent operations allowed.
47+
48+
Returns
49+
-------
50+
ConcurrentLimitLayer
51+
"""
3652

37-
@final
53+
class Layer:
54+
r"""
55+
Layer.
56+
57+
Layers are used to intercept the operations on the underlying storage.
58+
"""
59+
60+
@typing.final
3861
class MimeGuessLayer(Layer):
39-
def __init__(self) -> None: ...
62+
r"""
63+
MimeGuessLayer.
64+
65+
Create a layer that guesses MIME types for objects based on their
66+
paths or content.
67+
68+
This layer uses the `mime_guess` crate
69+
(see https://crates.io/crates/mime_guess) to infer the
70+
``Content-Type``.
71+
72+
Notes
73+
-----
74+
This layer will not override a ``Content-Type`` that has already
75+
been set, either manually or by the backend service. It is only
76+
applied if no content type is present.
77+
78+
A ``Content-Type`` is not guaranteed. If the file extension is
79+
uncommon or unknown, the content type will remain unset.
80+
"""
81+
82+
def __new__(cls) -> MimeGuessLayer:
83+
r"""
84+
Create a new MimeGuessLayer.
85+
86+
Returns
87+
-------
88+
MimeGuessLayer
89+
"""
90+
91+
@typing.final
92+
class RetryLayer(Layer):
93+
r"""
94+
RetryLayer.
95+
96+
A layer that retries operations that fail with temporary errors.
97+
98+
Operations are retried if they fail with an error for which
99+
`Error.is_temporary` returns `True`. If all retries are exhausted,
100+
the error is marked as persistent and then returned.
101+
102+
Notes
103+
-----
104+
After an operation on a `Reader` or `Writer` has failed through
105+
all retries, the object is in an undefined state. Reusing it
106+
can lead to exceptions.
107+
"""
108+
109+
def __new__(
110+
cls,
111+
max_times: builtins.int | None = None,
112+
factor: builtins.float | None = None,
113+
jitter: builtins.bool = False,
114+
max_delay: builtins.float | None = None,
115+
min_delay: builtins.float | None = None,
116+
) -> RetryLayer:
117+
r"""
118+
Create a new RetryLayer.
119+
120+
Parameters
121+
----------
122+
max_times : Optional[int]
123+
Maximum number of retry attempts. Defaults to ``3``.
124+
factor : Optional[float]
125+
Backoff factor applied between retries. Defaults to ``2.0``.
126+
jitter : bool
127+
Whether to apply jitter to the backoff. Defaults to ``False``.
128+
max_delay : Optional[float]
129+
Maximum delay (in seconds) between retries. Defaults to ``60.0``.
130+
min_delay : Optional[float]
131+
Minimum delay (in seconds) between retries. Defaults to ``1.0``.
132+
133+
Returns
134+
-------
135+
RetryLayer
136+
"""

0 commit comments

Comments
 (0)