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 8ca778fb1e fix(bindings/python): reject zero ConcurrentLimitLayer and
accept None kwargs in open (#8869)
8ca778fb1e is described below
commit 8ca778fb1e68564e41883f9ff04bcbdb019d3f30
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 22:12:07 2026 +0800
fix(bindings/python): reject zero ConcurrentLimitLayer and accept None
kwargs in open (#8869)
---
bindings/python/python/opendal/layers.pyi | 8 +++-
bindings/python/src/layers/concurrent_limit.rs | 12 ++++-
bindings/python/src/options.rs | 4 +-
.../tests/layers/test_concurrent_limit_layer.py | 39 ++++++++++++++++
bindings/python/tests/test_open_modes.py | 53 ++++++++++++++++++++++
5 files changed, 112 insertions(+), 4 deletions(-)
diff --git a/bindings/python/python/opendal/layers.pyi
b/bindings/python/python/opendal/layers.pyi
index 3868a7ca24..15f0a51a8a 100644
--- a/bindings/python/python/opendal/layers.pyi
+++ b/bindings/python/python/opendal/layers.pyi
@@ -66,11 +66,17 @@ class ConcurrentLimitLayer(Layer):
Parameters
----------
limit : int
- Maximum number of concurrent operations allowed.
+ Maximum number of concurrent operations allowed. Must be greater
+ than ``0``.
Returns
-------
ConcurrentLimitLayer
+
+ Raises
+ ------
+ ConfigInvalid
+ If ``limit`` is ``0``.
"""
@disjoint_base
diff --git a/bindings/python/src/layers/concurrent_limit.rs
b/bindings/python/src/layers/concurrent_limit.rs
index 87042d3a89..9f766e1e2d 100644
--- a/bindings/python/src/layers/concurrent_limit.rs
+++ b/bindings/python/src/layers/concurrent_limit.rs
@@ -44,14 +44,24 @@ impl ConcurrentLimitLayer {
/// Parameters
/// ----------
/// limit : int
- /// Maximum number of concurrent operations allowed.
+ /// Maximum number of concurrent operations allowed. Must be greater
+ /// than ``0``.
///
/// Returns
/// -------
/// ConcurrentLimitLayer
+ ///
+ /// Raises
+ /// ------
+ /// ConfigInvalid
+ /// If ``limit`` is ``0``.
#[new]
#[pyo3(signature = (limit))]
fn new(limit: usize) -> PyResult<PyClassInitializer<Self>> {
+ if limit == 0 {
+ return Err(ConfigInvalid::new_err("limit must be greater than 0"));
+ }
+
let concurrent_limit =
Self(ocore::layers::ConcurrentLimitLayer::new(limit));
let class =
PyClassInitializer::from(Layer(Box::new(concurrent_limit.clone())))
.add_subclass(concurrent_limit);
diff --git a/bindings/python/src/options.rs b/bindings/python/src/options.rs
index c66758df5b..15205c3147 100644
--- a/bindings/python/src/options.rs
+++ b/bindings/python/src/options.rs
@@ -73,11 +73,11 @@ where
T: FromPyObjectOwned<'py>,
{
match dict.get_item(name)? {
- Some(v) => v
+ Some(v) if !v.is_none() => v
.extract::<T>()
.map(Some)
.map_err(|err| map_exception(name, err.into())),
- None => Ok(None),
+ _ => Ok(None),
}
}
diff --git a/bindings/python/tests/layers/test_concurrent_limit_layer.py
b/bindings/python/tests/layers/test_concurrent_limit_layer.py
new file mode 100644
index 0000000000..e31647ff24
--- /dev/null
+++ b/bindings/python/tests/layers/test_concurrent_limit_layer.py
@@ -0,0 +1,39 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+
+import opendal
+from opendal.exceptions import ConfigInvalid
+
+
+def test_concurrent_limit_layer_rejects_zero():
+ with pytest.raises(ConfigInvalid):
+ opendal.layers.ConcurrentLimitLayer(0)
+
+
+def test_concurrent_limit_layer_allows_sync_operations():
+ op =
opendal.Operator("memory").layer(opendal.layers.ConcurrentLimitLayer(1))
+ op.write("test", b"hello")
+ assert op.read("test") == b"hello"
+
+
[email protected]
+async def test_concurrent_limit_layer_allows_async_operations():
+ op =
opendal.AsyncOperator("memory").layer(opendal.layers.ConcurrentLimitLayer(1))
+ await op.write("test", b"hello")
+ assert await op.read("test") == b"hello"
diff --git a/bindings/python/tests/test_open_modes.py
b/bindings/python/tests/test_open_modes.py
index c9e88ff77c..d303840c81 100644
--- a/bindings/python/tests/test_open_modes.py
+++ b/bindings/python/tests/test_open_modes.py
@@ -261,3 +261,56 @@ async def
test_async_open_conflicting_options(local_operator, mode, kwargs, matc
op = local_operator.to_async_operator()
with pytest.raises(ValueError, match=match):
await op.open("data", mode, **kwargs)
+
+
+NONE_WRITE_OPTIONS = {
+ "append": None,
+ "chunk": None,
+ "concurrent": None,
+ "cache_control": None,
+ "content_type": None,
+ "content_disposition": None,
+ "content_encoding": None,
+ "if_match": None,
+ "if_none_match": None,
+ "if_not_exists": None,
+ "user_metadata": None,
+}
+
+NONE_READ_OPTIONS = {
+ "version": None,
+ "concurrent": None,
+ "chunk": None,
+ "gap": None,
+ "offset": None,
+ "prefetch": None,
+ "size": None,
+ "if_match": None,
+ "if_none_match": None,
+ "if_modified_since": None,
+ "if_unmodified_since": None,
+ "content_type": None,
+ "cache_control": None,
+ "content_disposition": None,
+}
+
+
+def test_sync_open_none_options(local_operator):
+ op = local_operator
+ with op.open("data", "wb", **NONE_WRITE_OPTIONS) as file:
+ assert file.write(b"hello") == 5
+ with op.open("data", "rb", **NONE_READ_OPTIONS) as file:
+ assert file.read() == b"hello"
+ with pytest.raises(TypeError):
+ op.open("data", "rb", offset="invalid")
+
+
[email protected]
+async def test_async_open_none_options(local_operator):
+ op = local_operator.to_async_operator()
+ async with await op.open("data", "wb", **NONE_WRITE_OPTIONS) as file:
+ assert await file.write(b"hello") == 5
+ async with await op.open("data", "rb", **NONE_READ_OPTIONS) as file:
+ assert await file.read() == b"hello"
+ with pytest.raises(TypeError):
+ await op.open("data", "rb", offset="invalid")