This is an automated email from the ASF dual-hosted git repository. Xuanwo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 9b01160aa5 chore(bindings/python): bump pyo3 to 0.30.1 and
pyo3-async-runtimes to 0.30.0 (#8723)
9b01160aa5 is described below
commit 9b01160aa5ec9b054f9103358520364afa0dd6f6
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 05:25:51 2026 +0800
chore(bindings/python): bump pyo3 to 0.30.1 and pyo3-async-runtimes to
0.30.0 (#8723)
* chore(bindings/python): bump pyo3 to 0.30.1, pyo3-async-runtimes to
0.30.0 and maturin to 1.16
pyo3 and pyo3-async-runtimes must move to 0.30 together, so this
supersedes the Dependabot update that only bumped pyo3.
- Migrate File::readinto from the deprecated and unsound
PyBuffer::as_mut_slice to as_slice_ptr, still copying only the
bytes actually read so a short read leaves the buffer tail intact.
- Drop the deprecated skip_from_py_object options; pyo3 0.30 skips
FromPyObject for pyclass enums and subclasses by default. The
explicit from_py_object on Scheme is kept.
- Regenerate .pyi stubs with pyo3-introspection 0.30, which now
reports integer/float parameters as SupportsIndex/SupportsFloat,
marks non-subclassable pyclasses with @disjoint_base, and adds
__all__ plus submodule imports.
- Refresh DEPENDENCIES.rust.tsv via cargo deny list.
* chore(bindings/python): regenerate stubs under ruff 0.17.6
The stub-gen run on rebased main uses ruff 0.17.6, which removes the
duplicated __all__ emitted by pyo3-introspection 0.30.
* fix(bindings/python): handle zero-length and null buffers in
File::readinto
- Return early for zero-length buffers and empty reads so a NULL data
pointer never reaches as_slice_ptr, and error instead of panicking if
the pointer is still unavailable.
- Assert the read fits the target slice before the unsafe copy and note
the free-threaded no-concurrent-access requirement in the SAFETY
comment.
- Pin stub generation to --features abi3 so pyo3-introspection always
targets abi3-py311 regardless of the interpreter, and normalize
typing.disjoint_base to typing_extensions in postprocess_stubs for
interpreters where abi3 cannot apply.
- Add readinto tests for empty buffers and readonly empty buffers.
---
bindings/python/Cargo.toml | 4 +-
bindings/python/DEPENDENCIES.rust.tsv | 312 ++++++++++++----------
bindings/python/justfile | 5 +-
bindings/python/python/opendal/file.pyi | 20 +-
bindings/python/python/opendal/layers.pyi | 20 +-
bindings/python/python/opendal/operator.pyi | 50 ++--
bindings/python/scripts/postprocess_stubs.py | 25 +-
bindings/python/src/file.rs | 30 ++-
bindings/python/src/layers/capability_override.rs | 2 +-
bindings/python/src/layers/concurrent_limit.rs | 2 +-
bindings/python/src/layers/mime_guess.rs | 2 +-
bindings/python/src/layers/retry.rs | 2 +-
bindings/python/src/layers/timeout.rs | 2 +-
bindings/python/src/metadata.rs | 9 +-
bindings/python/tests/test_read.py | 36 +++
15 files changed, 316 insertions(+), 205 deletions(-)
diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml
index 342cfc6582..1dfcb606a5 100644
--- a/bindings/python/Cargo.toml
+++ b/bindings/python/Cargo.toml
@@ -213,12 +213,12 @@ opendal = { version = ">=0", path = "../../core",
features = [
"blocking",
"layers-mime-guess",
] }
-pyo3 = { version = "0.29.1", features = [
+pyo3 = { version = "0.30.1", features = [
"experimental-inspect",
"generate-import-lib",
"jiff-02",
] }
-pyo3-async-runtimes = { version = "0.29.0", features = ["tokio-runtime"] }
+pyo3-async-runtimes = { version = "0.30.0", features = ["tokio-runtime"] }
tokio = "1"
[profile.release]
diff --git a/bindings/python/DEPENDENCIES.rust.tsv
b/bindings/python/DEPENDENCIES.rust.tsv
index 55331d6d2c..4e9e35067b 100644
--- a/bindings/python/DEPENDENCIES.rust.tsv
+++ b/bindings/python/DEPENDENCIES.rust.tsv
@@ -1,23 +1,26 @@
crate Apache-2.0 Apache-2.0 WITH LLVM-exception BSD-2-Clause
BSD-3-Clause BSL-1.0 CC0-1.0 CDLA-Permissive-2.0 ISC
LGPL-2.1-or-later MIT MIT-0 MPL-2.0 Unicode-3.0 Unlicense
Zlib
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X X
X X X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X X
X X X
[email protected] X
[email protected] X
X
[email protected] X
X
@@ -32,19 +35,19 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X X
[email protected]
X X
[email protected]
X
[email protected]
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -54,17 +57,18 @@ [email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
@@ -73,7 +77,7 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -82,21 +86,21 @@ [email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -109,19 +113,26 @@ [email protected]
X
[email protected] X X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
@@ -133,6 +144,7 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -148,23 +160,24 @@ [email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
@@ -177,70 +190,75 @@ [email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X X
[email protected]
X X
[email protected]
X X
[email protected] X
X
[email protected] X
X
[email protected]
X X
[email protected]
X X
[email protected]
X X
[email protected]
X X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected]
X
[email protected]+lz4-1.10.0
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X X
[email protected] X
X
[email protected]
X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X X
X X
[email protected] X
X
[email protected] X
X
@@ -248,9 +266,11 @@ [email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X X
[email protected]
X
@@ -262,6 +282,7 @@ [email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
@@ -280,6 +301,7 @@ [email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
@@ -308,6 +330,7 @@ [email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
@@ -317,7 +340,13 @@ [email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
@@ -326,20 +355,20 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
@@ -347,22 +376,22 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected]
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X X
[email protected] X
X X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -371,41 +400,41 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected]
X
[email protected] X X
X
[email protected] X X
X
[email protected] X X
X
[email protected] X
X X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X X
[email protected]
X
@@ -417,6 +446,7 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -424,8 +454,8 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -433,6 +463,7 @@ [email protected] X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -442,18 +473,21 @@ [email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
[email protected] X
X
[email protected] X
X
@@ -464,7 +498,7 @@ [email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected]
X
[email protected]
X
@@ -473,8 +507,9 @@ [email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
[email protected] X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
@@ -484,9 +519,10 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
[email protected]
X
[email protected]
X
[email protected] X
X X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
X
@@ -494,8 +530,8 @@ [email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
@@ -518,37 +554,34 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X X
[email protected] X
X X
[email protected] X
X
[email protected] X
X
[email protected] X
X X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
X
[email protected]
X X
[email protected]
X X
[email protected]
X
[email protected]+wasi-snapshot-preview1 X X
X
[email protected]+wasi-0.2.4 X X
X
[email protected]+wasi-0.2.12 X X
X
[email protected] X X
X
[email protected] X X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected] X
[email protected] X
[email protected] X X
X
[email protected]
X
[email protected] X
[email protected] X X
X
[email protected] X
X
[email protected] X
X
@@ -566,54 +599,49 @@ [email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X
X
[email protected] X X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected]
X
[email protected] X
X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected] X
[email protected]
X
[email protected]
X
[email protected] X X
X
[email protected] X X
X
[email protected]
X
[email protected]
X
[email protected] X
X
[email protected] X
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected]
X
[email protected] X
[email protected] X
[email protected]+zstd.1.5.7 X X
diff --git a/bindings/python/justfile b/bindings/python/justfile
index dbb6d7b181..3be83bc764 100644
--- a/bindings/python/justfile
+++ b/bindings/python/justfile
@@ -55,7 +55,10 @@ clean:
stub-gen: setup
@echo "{{ BOLD }}--- Generating Python type stubs ---{{ NORMAL }}"
@cargo run --quiet --manifest-path=../../dev/Cargo.toml -- generate -l
python
- @uv run maturin develop --generate-stubs
+ ## `--features abi3` pins pyo3-introspection to the minimum supported
+ ## Python (3.11 via `abi3-py311`), so generated stubs do not depend
+ ## on the interpreter version that runs the build.
+ @uv run maturin develop --generate-stubs --features abi3
## This is temporary till the functionalities land in pyo3-introspection.
ref: https://github.com/PyO3/pyo3/issues/5137
@echo "{{ BOLD }}--- Post processing generated stubs ---{{ NORMAL }}"
@uv run python scripts/postprocess_stubs.py
diff --git a/bindings/python/python/opendal/file.pyi
b/bindings/python/python/opendal/file.pyi
index 5d5365ceab..569e8c6755 100644
--- a/bindings/python/python/opendal/file.pyi
+++ b/bindings/python/python/opendal/file.pyi
@@ -18,7 +18,7 @@
import collections.abc
import types
import typing
-from typing import Any, final
+from typing import Any, SupportsIndex, final
__all__ = ["AsyncFile", "File"]
@@ -58,7 +58,9 @@ class AsyncFile:
coroutine
An awaitable that returns True if this file is closed.
"""
- def read(self, /, size: int | None = None) ->
collections.abc.Awaitable[bytes]:
+ def read(
+ self, /, size: SupportsIndex | None = None
+ ) -> collections.abc.Awaitable[bytes]:
"""
Read at most `size` bytes from this file asynchronously.
@@ -79,7 +81,9 @@ class AsyncFile:
coroutine
An awaitable that returns the bytes read from the stream.
"""
- def read_buffered(self, /, size: int) -> collections.abc.Awaitable[bytes]:
+ def read_buffered(
+ self, /, size: SupportsIndex
+ ) -> collections.abc.Awaitable[bytes]:
"""
Read up to `size` bytes by combining immediately available data.
@@ -112,7 +116,9 @@ class AsyncFile:
coroutine
An awaitable that returns True if this file can be read from.
"""
- def seek(self, /, pos: int, whence: int = 0) ->
collections.abc.Awaitable[int]:
+ def seek(
+ self, /, pos: SupportsIndex, whence: SupportsIndex = 0
+ ) -> collections.abc.Awaitable[int]:
"""
Change the position of this file to the given byte offset.
@@ -239,7 +245,7 @@ class File:
buffered until more data arrives or `close()` completes the write.
Is a no-op if the file is not `writable`.
"""
- def read(self, /, size: int | None = None) -> bytes:
+ def read(self, /, size: SupportsIndex | None = None) -> bytes:
"""
Read at most `size` bytes from this file.
@@ -283,7 +289,7 @@ class File:
int
The number of bytes read.
"""
- def readline(self, /, size: int | None = None) -> bytes:
+ def readline(self, /, size: SupportsIndex | None = None) -> bytes:
"""
Read one line from this file.
@@ -304,7 +310,7 @@ class File:
bytes
The bytes read from this file.
"""
- def seek(self, /, pos: int, whence: int = 0) -> int:
+ def seek(self, /, pos: SupportsIndex, whence: SupportsIndex = 0) -> int:
"""
Change the position of this file to the given byte offset.
diff --git a/bindings/python/python/opendal/layers.pyi
b/bindings/python/python/opendal/layers.pyi
index 954c86e082..3868a7ca24 100644
--- a/bindings/python/python/opendal/layers.pyi
+++ b/bindings/python/python/opendal/layers.pyi
@@ -15,7 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-from typing import final
+from typing import SupportsFloat, SupportsIndex, final
+
+from typing_extensions import disjoint_base
__all__ = [
"CapabilityOverrideLayer",
@@ -57,7 +59,7 @@ class ConcurrentLimitLayer(Layer):
application does not exceed the limit.
"""
- def __new__(cls, /, limit: int) -> ConcurrentLimitLayer:
+ def __new__(cls, /, limit: SupportsIndex) -> ConcurrentLimitLayer:
"""
Create a new ConcurrentLimitLayer.
@@ -71,6 +73,7 @@ class ConcurrentLimitLayer(Layer):
ConcurrentLimitLayer
"""
+@disjoint_base
class Layer:
"""
Base class for all layers.
@@ -131,11 +134,11 @@ class RetryLayer(Layer):
def __new__(
cls,
/,
- max_times: int | None = None,
- factor: float | None = None,
+ max_times: SupportsIndex | None = None,
+ factor: SupportsFloat | SupportsIndex | None = None,
jitter: bool = False,
- max_delay: float | None = None,
- min_delay: float | None = None,
+ max_delay: SupportsFloat | SupportsIndex | None = None,
+ min_delay: SupportsFloat | SupportsIndex | None = None,
) -> RetryLayer:
"""
Create a new RetryLayer.
@@ -183,7 +186,10 @@ class TimeoutLayer(Layer):
"""
def __new__(
- cls, /, timeout: float | None = None, io_timeout: float | None = None
+ cls,
+ /,
+ timeout: SupportsFloat | SupportsIndex | None = None,
+ io_timeout: SupportsFloat | SupportsIndex | None = None,
) -> TimeoutLayer:
"""
Create a new TimeoutLayer.
diff --git a/bindings/python/python/opendal/operator.pyi
b/bindings/python/python/opendal/operator.pyi
index 7fb834d953..f2136d16fd 100644
--- a/bindings/python/python/opendal/operator.pyi
+++ b/bindings/python/python/opendal/operator.pyi
@@ -18,7 +18,7 @@
import collections.abc
from datetime import datetime
from os import PathLike
-from typing import Any, final
+from typing import Any, SupportsIndex, final
from typing_extensions import Unpack
@@ -293,7 +293,7 @@ class AsyncOperator:
/,
path: str | PathLike[str],
*,
- limit: int | None = None,
+ limit: SupportsIndex | None = None,
start_after: str | None = None,
recursive: bool | None = None,
versions: bool | None = None,
@@ -359,7 +359,7 @@ class AsyncOperator:
self,
/,
path: str | PathLike[str],
- expire_second: int,
+ expire_second: SupportsIndex,
*,
version: str | None = None,
) -> collections.abc.Awaitable[PresignedRequest]:
@@ -384,7 +384,7 @@ class AsyncOperator:
self,
/,
path: str | PathLike[str],
- expire_second: int,
+ expire_second: SupportsIndex,
*,
version: str | None = None,
if_match: str | None = None,
@@ -430,7 +430,7 @@ class AsyncOperator:
self,
/,
path: str | PathLike[str],
- expire_second: int,
+ expire_second: SupportsIndex,
*,
version: str | None = None,
if_match: str | None = None,
@@ -476,7 +476,7 @@ class AsyncOperator:
self,
/,
path: str | PathLike[str],
- expire_second: int,
+ expire_second: SupportsIndex,
*,
content_type: str | None = None,
content_disposition: str | None = None,
@@ -524,12 +524,12 @@ class AsyncOperator:
path: str | PathLike[str],
*,
version: str | None = None,
- concurrent: int | None = None,
- chunk: int | None = None,
- gap: int | None = None,
- offset: int | None = None,
- prefetch: int | None = None,
- size: int | None = None,
+ concurrent: SupportsIndex | None = None,
+ chunk: SupportsIndex | None = None,
+ gap: SupportsIndex | None = None,
+ offset: SupportsIndex | None = None,
+ prefetch: SupportsIndex | None = None,
+ size: SupportsIndex | None = None,
if_match: str | None = None,
if_none_match: str | None = None,
if_modified_since: datetime | None = None,
@@ -631,7 +631,7 @@ class AsyncOperator:
/,
path: str | PathLike[str],
*,
- limit: int | None = None,
+ limit: SupportsIndex | None = None,
start_after: str | None = None,
versions: bool | None = None,
deleted: bool | None = None,
@@ -720,8 +720,8 @@ class AsyncOperator:
bs: bytes,
*,
append: bool | None = None,
- chunk: int | None = None,
- concurrent: int | None = None,
+ chunk: SupportsIndex | None = None,
+ concurrent: SupportsIndex | None = None,
cache_control: str | None = None,
content_type: str | None = None,
content_disposition: str | None = None,
@@ -1004,7 +1004,7 @@ class Operator:
/,
path: str | PathLike[str],
*,
- limit: int | None = None,
+ limit: SupportsIndex | None = None,
start_after: str | None = None,
recursive: bool | None = None,
versions: bool | None = None,
@@ -1072,12 +1072,12 @@ class Operator:
path: str | PathLike[str],
*,
version: str | None = None,
- concurrent: int | None = None,
- chunk: int | None = None,
- gap: int | None = None,
- offset: int | None = None,
- prefetch: int | None = None,
- size: int | None = None,
+ concurrent: SupportsIndex | None = None,
+ chunk: SupportsIndex | None = None,
+ gap: SupportsIndex | None = None,
+ offset: SupportsIndex | None = None,
+ prefetch: SupportsIndex | None = None,
+ size: SupportsIndex | None = None,
if_match: str | None = None,
if_none_match: str | None = None,
if_modified_since: datetime | None = None,
@@ -1167,7 +1167,7 @@ class Operator:
/,
path: str | PathLike[str],
*,
- limit: int | None = None,
+ limit: SupportsIndex | None = None,
start_after: str | None = None,
versions: bool | None = None,
deleted: bool | None = None,
@@ -1256,8 +1256,8 @@ class Operator:
bs: bytes,
*,
append: bool | None = None,
- chunk: int | None = None,
- concurrent: int | None = None,
+ chunk: SupportsIndex | None = None,
+ concurrent: SupportsIndex | None = None,
cache_control: str | None = None,
content_type: str | None = None,
content_disposition: str | None = None,
diff --git a/bindings/python/scripts/postprocess_stubs.py
b/bindings/python/scripts/postprocess_stubs.py
index 12ca606903..010eac4b0c 100644
--- a/bindings/python/scripts/postprocess_stubs.py
+++ b/bindings/python/scripts/postprocess_stubs.py
@@ -88,14 +88,35 @@ def fix_incomplete_exceptions() -> None:
path.write_text(EXCEPTIONS_STUB)
+def pin_disjoint_base_import(text: str) -> str:
+ """Import ``disjoint_base`` from ``typing_extensions`` instead of
``typing``.
+
+ PyO3 emits ``from typing import ..., disjoint_base`` when the build
+ interpreter targets Python 3.15+, where ``typing.disjoint_base`` exists.
+ The stubs must import it from ``typing_extensions`` so they also work on
+ the minimum supported Python (3.11).
+ """
+ lines = []
+ for line in text.splitlines(keepends=True):
+ if line.startswith("from typing import") and "disjoint_base" in line:
+ names = [n.strip() for n in line[len("from typing import")
:].split(",")]
+ names.remove("disjoint_base")
+ line = f"from typing import {', '.join(names)}\n" if names else ""
+ line += "from typing_extensions import disjoint_base\n"
+ lines.append(line)
+ return "".join(lines)
+
+
def relocate() -> None:
"""Move the stubs to the public ``opendal/<name>.pyi`` paths."""
for name in SUBMODULES:
- text = (GEN / f"{name}.pyi").read_text()
+ text = pin_disjoint_base_import((GEN / f"{name}.pyi").read_text())
(PKG / f"{name}.pyi").write_text(IMPORTS.get(name, "") + text)
# Stub for the ``opendal/_opendal.*.so`` extension itself.
- (PKG / "_opendal.pyi").write_text((GEN / "__init__.pyi").read_text())
+ (PKG / "_opendal.pyi").write_text(
+ pin_disjoint_base_import((GEN / "__init__.pyi").read_text())
+ )
for child in GEN.iterdir():
child.unlink()
diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs
index c47b22010f..af6735345a 100644
--- a/bindings/python/src/file.rs
+++ b/bindings/python/src/file.rs
@@ -221,17 +221,35 @@ impl File {
check_runtime_process()?;
let size = buffer.len_bytes();
+ if size == 0 {
+ return Ok(0);
+ }
// Wait using owned storage, without exposing the Python buffer to I/O.
let data = py.detach(|| reader.read_buffer(size))?;
let len = data.len();
- let target = buffer.as_mut_slice(py).expect("buffer was validated
above");
+ if len == 0 {
+ return Ok(0);
+ }
+ let target = buffer
+ .as_slice_ptr()
+ .ok_or_else(|| PyIOError::new_err("Buffer pointer is null or not C
contiguous."))?;
+ assert!(len <= target.len());
let mut offset = 0;
for chunk in data {
- for (dst, src) in target[offset..offset + chunk.len()]
- .iter()
- .zip(chunk.iter())
- {
- dst.set(*src);
+ // SAFETY: the buffer is writable, C-contiguous, and `as_slice_ptr`
+ // covers `target.len()` elements with `len <= target.len()`, so
+ // writing `chunk.len()` bytes at `offset` stays within the buffer.
+ // `data` is owned storage that cannot overlap the Python buffer.
+ // Callers must not mutate or read the same buffer from another
+ // thread while `readinto` runs (possible under free-threaded
+ // Python). Only the prefix holding `len` bytes is overwritten; the
+ // buffer tail is left untouched.
+ unsafe {
+ std::ptr::copy_nonoverlapping(
+ chunk.as_ptr(),
+ target.as_ptr().cast::<u8>().add(offset),
+ chunk.len(),
+ );
}
offset += chunk.len();
}
diff --git a/bindings/python/src/layers/capability_override.rs
b/bindings/python/src/layers/capability_override.rs
index 8a7b1a90ae..c089198e3b 100644
--- a/bindings/python/src/layers/capability_override.rs
+++ b/bindings/python/src/layers/capability_override.rs
@@ -21,7 +21,7 @@ use crate::*;
use opendal::Operator;
/// A layer that overrides the full capability exposed by an operator.
-#[pyclass(module = "opendal.layers", extends=Layer, skip_from_py_object)]
+#[pyclass(module = "opendal.layers", extends=Layer)]
#[derive(Clone)]
pub struct CapabilityOverrideLayer(ocore::layers::CapabilityOverrideLayer);
diff --git a/bindings/python/src/layers/concurrent_limit.rs
b/bindings/python/src/layers/concurrent_limit.rs
index bbdfc9de99..87042d3a89 100644
--- a/bindings/python/src/layers/concurrent_limit.rs
+++ b/bindings/python/src/layers/concurrent_limit.rs
@@ -28,7 +28,7 @@ use opendal::Operator;
/// allows you to reuse the same layer across multiple operators, ensuring
/// that the total number of concurrent requests across the entire
/// application does not exceed the limit.
-#[pyclass(module = "opendal.layers", extends = Layer, skip_from_py_object)]
+#[pyclass(module = "opendal.layers", extends = Layer)]
#[derive(Clone)]
pub struct ConcurrentLimitLayer(ocore::layers::ConcurrentLimitLayer);
diff --git a/bindings/python/src/layers/mime_guess.rs
b/bindings/python/src/layers/mime_guess.rs
index af99855e29..78cca65908 100644
--- a/bindings/python/src/layers/mime_guess.rs
+++ b/bindings/python/src/layers/mime_guess.rs
@@ -34,7 +34,7 @@ use opendal::Operator;
///
/// A ``Content-Type`` is not guaranteed. If the file extension is
/// uncommon or unknown, the content type will remain unset.
-#[pyclass(module = "opendal.layers", extends = Layer, skip_from_py_object)]
+#[pyclass(module = "opendal.layers", extends = Layer)]
#[derive(Clone)]
pub struct MimeGuessLayer(ocore::layers::MimeGuessLayer);
diff --git a/bindings/python/src/layers/retry.rs
b/bindings/python/src/layers/retry.rs
index dc1f9806a1..3800d36233 100644
--- a/bindings/python/src/layers/retry.rs
+++ b/bindings/python/src/layers/retry.rs
@@ -33,7 +33,7 @@ use opendal::Operator;
/// After an operation on a `Reader` or `Writer` has failed through
/// all retries, the object is in an undefined state. Reusing it
/// can lead to exceptions.
-#[pyclass(module = "opendal.layers", extends=Layer, skip_from_py_object)]
+#[pyclass(module = "opendal.layers", extends=Layer)]
#[derive(Clone)]
pub struct RetryLayer(ocore::layers::RetryLayer);
diff --git a/bindings/python/src/layers/timeout.rs
b/bindings/python/src/layers/timeout.rs
index 08c57b40f0..1969d66a9a 100644
--- a/bindings/python/src/layers/timeout.rs
+++ b/bindings/python/src/layers/timeout.rs
@@ -50,7 +50,7 @@ fn parse_timeout_secs(name: &str, secs: f64) ->
PyResult<Duration> {
/// -----
/// A small amount of overhead is added to IO operations to implement the
/// timeout correctly.
-#[pyclass(module = "opendal.layers", extends = Layer, skip_from_py_object)]
+#[pyclass(module = "opendal.layers", extends = Layer)]
#[derive(Clone)]
pub struct TimeoutLayer(ocore::layers::TimeoutLayer);
diff --git a/bindings/python/src/metadata.rs b/bindings/python/src/metadata.rs
index c4aca10a82..eedae51de1 100644
--- a/bindings/python/src/metadata.rs
+++ b/bindings/python/src/metadata.rs
@@ -186,14 +186,7 @@ impl Metadata {
/// EntryMode
///
/// The mode of an entry, indicating if it is a file or a directory.
-#[pyclass(
- eq,
- eq_int,
- hash,
- frozen,
- module = "opendal.types",
- skip_from_py_object
-)]
+#[pyclass(eq, eq_int, hash, frozen, module = "opendal.types")]
#[pyo3(rename_all = "PascalCase")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EntryMode {
diff --git a/bindings/python/tests/test_read.py
b/bindings/python/tests/test_read.py
index ecb7d4c3c8..133207835e 100644
--- a/bindings/python/tests/test_read.py
+++ b/bindings/python/tests/test_read.py
@@ -410,3 +410,39 @@ def test_sync_readinto_buffer_boundaries(operator):
assert target == b"??abcdef??"
finally:
operator.delete(filename)
+
+
[email protected]_capability("read", "write", "delete")
+def test_sync_readinto_empty_buffers(operator):
+ filename = f"readinto_empty_{uuid4()}"
+ operator.write(filename, b"abcdef")
+ try:
+ with operator.open(filename, "rb") as reader:
+ # Zero-length buffers may carry a NULL data pointer; `readinto`
+ # must return 0 instead of panicking.
+ assert reader.readinto(bytearray()) == 0
+ assert reader.readinto(memoryview(bytearray(0))) == 0
+ assert reader.tell() == 0
+
+ with operator.open(filename, "rb") as reader:
+ # A zero-length read at EOF also returns 0 without touching the
+ # buffer pointer.
+ reader.read()
+ assert reader.readinto(bytearray(4)) == 0
+ finally:
+ operator.delete(filename)
+
+
[email protected]_capability("read", "write", "delete")
+def test_sync_readinto_readonly_empty_buffer(operator):
+ filename = f"readinto_empty_readonly_{uuid4()}"
+ operator.write(filename, b"abcdef")
+ try:
+ with (
+ operator.open(filename, "rb") as reader,
+ pytest.raises(OSError, match="not writable"),
+ ):
+ # A zero-length but readonly buffer is still rejected.
+ reader.readinto(memoryview(b""))
+ finally:
+ operator.delete(filename)
