Skip to content

Commit 53b8de7

Browse files
committed
Stubs for Metadata, Entry, and EntryMode
1 parent ae62b58 commit 53b8de7

File tree

5 files changed

+240
-89
lines changed

5 files changed

+240
-89
lines changed

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
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# This file is automatically generated by pyo3_stub_gen
19+
# ruff: noqa: E501, F401
20+
21+
import builtins
22+
import datetime
23+
import enum
24+
import typing
25+
26+
@typing.final
27+
class Entry:
28+
r"""
29+
Entry.
30+
31+
An entry representing a path and its associated metadata.
32+
33+
Notes
34+
-----
35+
If this entry is a directory, ``path`` **must** end with ``/``.
36+
Otherwise, ``path`` **must not** end with ``/``.
37+
"""
38+
39+
@property
40+
def path(self) -> builtins.str:
41+
r"""The path of entry relative to the operator's root."""
42+
@property
43+
def name(self) -> builtins.str:
44+
r"""The name of entry, representing the last segment of the path."""
45+
@property
46+
def metadata(self) -> Metadata:
47+
r"""The metadata of this entry."""
48+
49+
@typing.final
50+
class Metadata:
51+
r"""
52+
The metadata of an ``Entry``.
53+
54+
The metadata is always tied to a specific context and is not a global
55+
state. For example, two versions of the same path might have different
56+
content lengths.
57+
58+
Notes
59+
-----
60+
In systems that support versioning, such as AWS S3, the metadata may
61+
represent a specific version of a file. Use :attr:`version` to get
62+
the version of a file if it is available.
63+
"""
64+
65+
@property
66+
def content_disposition(self) -> builtins.str | None:
67+
r"""The content disposition of this entry."""
68+
@property
69+
def content_length(self) -> builtins.int:
70+
r"""The content length of this entry."""
71+
@property
72+
def content_md5(self) -> builtins.str | None:
73+
r"""The content MD5 of this entry."""
74+
@property
75+
def content_type(self) -> builtins.str | None:
76+
r"""The content type of this entry."""
77+
@property
78+
def content_encoding(self) -> builtins.str | None:
79+
r"""The content encoding of this entry."""
80+
@property
81+
def etag(self) -> builtins.str | None:
82+
r"""The ETag of this entry."""
83+
@property
84+
def mode(self) -> EntryMode:
85+
r"""The mode of this entry."""
86+
@property
87+
def is_file(self) -> builtins.bool:
88+
r"""Whether this entry is a file."""
89+
@property
90+
def is_dir(self) -> builtins.bool:
91+
r"""Whether this entry is a directory."""
92+
@property
93+
def last_modified(self) -> datetime.datetime:
94+
r"""The last modified timestamp of this entry."""
95+
@property
96+
def version(self) -> builtins.str | None:
97+
r"""The version of this entry."""
98+
@property
99+
def user_metadata(self) -> builtins.dict[builtins.str, builtins.str] | None:
100+
r"""The user-defined metadata of this entry."""
101+
102+
@typing.final
103+
class EntryMode(enum.Enum):
104+
r"""
105+
EntryMode.
106+
107+
The mode of an entry, indicating if it is a file or a directory.
108+
"""
109+
110+
File = ...
111+
r"""
112+
The entry is a file and has data to read.
113+
"""
114+
Dir = ...
115+
r"""
116+
The entry is a directory and can be listed.
117+
"""
118+
Unknown = ...
119+
r"""
120+
The mode of the entry is unknown.
121+
"""
122+
123+
def is_file(self) -> builtins.bool:
124+
r"""
125+
Check if the entry mode is `File`.
126+
127+
Returns
128+
-------
129+
bool
130+
True if the entry is a file.
131+
"""
132+
def is_dir(self) -> builtins.bool:
133+
r"""
134+
Check if the entry mode is `Dir`.
135+
136+
Returns
137+
-------
138+
bool
139+
True if the entry is a directory.
140+
"""

bindings/python/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ fn _opendal(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
5959
[Layer, RetryLayer, ConcurrentLimitLayer, MimeGuessLayer]
6060
)?;
6161

62-
m.add_class::<Entry>()?;
63-
m.add_class::<EntryMode>()?;
64-
m.add_class::<Metadata>()?;
62+
// Types module
63+
add_pymodule!(py, m, "types", [Entry, EntryMode, Metadata])?;
64+
6565
m.add_class::<PresignedRequest>()?;
6666

6767
m.add_class::<WriteOptions>()?;

0 commit comments

Comments
 (0)