Copilot commented on code in PR #7878:
URL: https://github.com/apache/opendal/pull/7878#discussion_r3535763893


##########
bindings/python/src/layers/mod.rs:
##########
@@ -0,0 +1,45 @@
+// 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.
+
+//! Python layer bindings.
+//!
+//! Each layer lives in its own module so new layers can be added without 
growing
+//! a single file. The concrete types are re-exported here (keeping 
`crate::<Layer>`
+//! paths working) and registered on the flat `opendal.layers` Python module.

Review Comment:
   The rustdoc text `crate::<Layer>` is not a valid Rust path syntax and is 
likely a typo. This could confuse readers trying to locate the types after the 
refactor; consider rewording to refer to `crate::layers::...` / existing 
`crate::layers::*` paths instead.



##########
bindings/python/src/layers/retry.rs:
##########
@@ -0,0 +1,103 @@
+// 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.
+
+use std::time::Duration;
+
+use super::Layer;
+use super::PythonLayer;
+use crate::*;
+use opendal::Operator;
+
+/// A layer that retries operations that fail with temporary errors.
+///
+/// Operations are retried if they fail with an error for which
+/// `Error.is_temporary` returns `True`. If all retries are exhausted,
+/// the error is marked as persistent and then returned.
+///
+/// Notes
+/// -----
+/// 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)]
+#[derive(Clone)]
+pub struct RetryLayer(ocore::layers::RetryLayer);
+
+impl PythonLayer for RetryLayer {
+    fn layer(&self, op: Operator) -> Operator {
+        op.layer(self.0.clone())
+    }
+}
+#[pymethods]
+impl RetryLayer {
+    /// Create a new RetryLayer.
+    ///
+    /// Parameters
+    /// ----------
+    /// max_times : Optional[int]
+    ///     Maximum number of retry attempts. Defaults to ``3``.
+    /// factor : Optional[float]
+    ///     Backoff factor applied between retries. Defaults to ``2.0``.
+    /// jitter : bool
+    ///     Whether to apply jitter to the backoff. Defaults to ``False``.
+    /// max_delay : Optional[float]
+    ///     Maximum delay (in seconds) between retries. Defaults to ``60.0``.
+    /// min_delay : Optional[float]
+    ///     Minimum delay (in seconds) between retries. Defaults to ``1.0``.
+    ///
+    /// Returns
+    /// -------
+    /// RetryLayer
+    #[new]
+    #[pyo3(signature = (
+        max_times = None,
+        factor = None,
+        jitter = false,
+        max_delay = None,
+        min_delay = None
+    ))]
+    fn new(
+        max_times: Option<usize>,
+        factor: Option<f32>,
+        jitter: bool,
+        max_delay: Option<f64>,
+        min_delay: Option<f64>,
+    ) -> PyResult<PyClassInitializer<Self>> {
+        let mut retry = ocore::layers::RetryLayer::default();
+        if let Some(max_times) = max_times {
+            retry = retry.with_max_times(max_times);
+        }
+        if let Some(factor) = factor {
+            retry = retry.with_factor(factor);
+        }

Review Comment:
   `ocore::layers::RetryLayer::with_factor` is documented to panic when `factor 
< 1.0`. Exposing it directly to Python means a user-provided `factor` like 
`0.5` can trigger a Rust panic during `__new__`, which can crash the Python 
process (or at least raise an uncatchable panic) instead of returning a normal 
exception. Validate `factor` before calling `with_factor` and return a 
`ValueError` for invalid inputs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to