Xuanwo commented on code in PR #9421:
URL: https://github.com/apache/opendal/pull/9421#discussion_r4736148823
##########
bindings/python/src/operator.rs:
##########
@@ -143,8 +145,15 @@ fn extract_delete_paths(paths: &Bound<'_, PyAny>) ->
PyResult<Vec<String>> {
paths
.try_iter()?
.map(|entry| {
- let path = entry?.extract::<PathBuf>()?;
- Ok(path.to_string_lossy().into_owned())
+ let entry = entry?;
+ let (path, opts) = match entry.cast::<PyTuple>() {
Review Comment:
`delete_many` can delete an unrelated object when a tuple subclass
implements `__fspath__`. In both bindings, the example below deleted `item` and
left `scoped/item`. The base wheel deleted `scoped/item` and kept `item`.
Please give `PathLike` entries their existing path interpretation before
handling `(path, options)` pairs, and keep converting the full iterable ahead
of the first deletion.
<details><summary>Memory reproducer</summary>
```python
from typing import NamedTuple
from opendal import Operator
class ScopedPath(NamedTuple):
name: str
attributes: dict[str, str]
def __fspath__(self) -> str:
return f"scoped/{self.name}"
op = Operator("memory")
path = ScopedPath("item", {})
op.write("item", b"unrelated")
op.write(path, b"selected")
op.delete_many([path])
assert (op.exists(path), op.exists("item")) == (False, True)
```
</details>
##########
bindings/python/python/opendal/options.py:
##########
@@ -140,6 +143,20 @@ class ReadKwargs(TypedDict, total=False):
without accessing storage. When `size` is positive, a file that ends
before `offset` plus `size` fails the read.
"""
+ limit: int | None
Review Comment:
`OpenKwargs` inherits this integer `limit`. Mypy and Pyright accept
`op.open("item", "rb", limit=4)` from the installed wheel, and both sync and
async `open` raise `TypeError` for it in read or write mode. Please let callers
omit `limit` or supply `None` to `open()`, and keep the integer limit on
`read()`.
##########
bindings/python/src/operator.rs:
##########
@@ -2163,26 +2521,93 @@ impl AsyncOperator {
///
/// Parameters
/// ----------
- /// paths : Iterable[str | PathLike[str]]
- /// The paths to delete. A single path is not accepted.
+ /// paths : Iterable[DeleteEntry]
+ /// The paths to delete. A `(path, options)` pair deletes `path` with
+ /// the `delete()` keyword arguments in `options`, such as
+ /// `{"if_not_changed": metadata}`, and raises `TypeError` for an
+ /// unknown key. A single path is not accepted.
+ /// concurrent : int, optional
+ /// The maximum number of backend delete tasks in flight. Each task
+ /// deletes one path, or one batch where the service deletes in
+ /// batches. Defaults to one task at a time.
///
/// Returns
/// -------
/// Awaitable[None]
/// An awaitable that completes when deletion finishes.
- #[pyo3(signature = (paths: "collections.abc.Iterable[str |
PathLike[str]]") -> "collections.abc.Awaitable[None]")]
+ #[pyo3(signature = (paths: "collections.abc.Iterable[DeleteEntry]", *,
concurrent=None) -> "collections.abc.Awaitable[None]")]
pub fn delete_many<'p>(
&'p self,
py: Python<'p>,
paths: &Bound<'_, PyAny>,
+ concurrent: Option<usize>,
) -> PyResult<Bound<'p, PyAny>> {
- let paths = extract_delete_paths(paths)?;
+ let paths = extract_delete_entries(paths)?;
+ let opts = DeleterOptions { concurrent };
let this = self.core.clone();
future_into_py(py, async move {
if paths.is_empty() {
return Ok(());
}
- this.delete_iter(paths).await.map_err(format_pyerr)
+ let mut deleter = this
+ .deleter_options(opts.into())
+ .await
+ .map_err(format_pyerr)?;
+ deleter.delete_iter(paths).await.map_err(format_pyerr)?;
+ deleter.close().await.map_err(format_pyerr)
+ })
+ }
+
+ /// Restore a file from its latest deleted state, or restore a version.
+ ///
+ /// Restoring a path that is already live succeeds. Without a live file or
+ /// a recoverable deleted state, `restore()` raises `NotFound`.
+ ///
+ /// Parameters
+ /// ----------
+ /// path : str
+ /// The path to the file.
+ /// version : str, optional
+ /// The version to restore as the current version. Requires
+ /// `restore_with_version`.
+ /// if_not_exists : bool, optional
+ /// If True, restore only when no file exists at `path`. Requires
+ /// `version` and `restore_with_if_not_exists`.
+ ///
+ /// Raises
+ /// ------
+ /// ConfigInvalid
+ /// If `if_not_exists` is set without `version`.
+ /// ConditionNotMatch
+ /// If `if_not_exists` is True and a file exists at `path`.
+ /// NotFound
+ /// If neither a live file nor a recoverable deleted state exists.
+ /// Unsupported
+ /// If the service does not support restore, `version`, or
+ /// `if_not_exists`.
+ ///
+ /// Returns
+ /// -------
+ /// coroutine
+ /// An awaitable that completes when the file is restored.
+ #[pyo3(signature = (path, *, version=None, if_not_exists=None) ->
"collections.abc.Awaitable[None]")]
+ pub fn restore<'p>(
+ &'p self,
+ py: Python<'p>,
+ path: PathBuf,
+ version: Option<String>,
+ if_not_exists: Option<bool>,
+ ) -> PyResult<Bound<'p, PyAny>> {
+ let this = self.core.clone();
+ let path = path.to_string_lossy().to_string();
+ let opts = RestoreOptions {
+ version,
+ if_not_exists,
+ };
+ future_into_py(py, async move {
+ this.restore_options(&path, opts)
Review Comment:
`await AsyncOperator.restore(path)` returns `()` on success. In a versioned
Silo bucket I wrote a key, deleted it, awaited `restore`, and read back the
expected bytes. `assert result is None` fails despite the `Awaitable[None]`
stub. Please return Python `None` when the restore succeeds.
--
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]