Copilot commented on code in PR #7869:
URL: https://github.com/apache/opendal/pull/7869#discussion_r3531670474
##########
bindings/python/src/operator.rs:
##########
@@ -753,6 +881,52 @@ impl AsyncOperator {
core: build_operator(&scheme, map.clone())?,
__scheme: scheme,
__map: map,
+ __from_uri: false,
+ })
+ }
+
+ /// Create a new `AsyncOperator` from a URI string.
+ ///
+ /// The URI encodes the scheme and configuration in a single string, e.g.
+ /// ``memory://`` or ``s3://bucket/path?region=us-east-1``. The scheme must
+ /// belong to a service enabled in this build.
+ ///
+ /// Parameters
+ /// ----------
+ /// uri : str
+ /// The URI of the service.
+ /// **kwargs : dict
+ /// Extra options that override or supplement values encoded in the
URI.
+ ///
+ /// Returns
+ /// -------
+ /// AsyncOperator
+ /// The new async operator.
+ ///
+ /// Examples
+ /// --------
+ /// >>> import opendal
+ /// >>> op = opendal.AsyncOperator.from_uri("memory://")
+ /// >>> op = opendal.AsyncOperator.from_uri("s3://bucket/path",
region="us-east-1")
+ #[classmethod]
+ #[pyo3(signature = (uri, **kwargs))]
+ pub fn from_uri(
+ _cls: &Bound<PyType>,
+ uri: &str,
+ kwargs: Option<&Bound<PyDict>>,
+ ) -> PyResult<Self> {
+ let map = kwargs
+ .map(|v| {
+ v.extract::<HashMap<String, String>>()
+ .expect("must be valid hashmap")
+ })
+ .unwrap_or_default();
Review Comment:
`AsyncOperator.from_uri` uses `expect("must be valid hashmap")` when
extracting `kwargs`, which can panic and abort the interpreter on invalid
input. Prefer propagating the `extract` error as a `PyErr`.
--
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]