chitralverma opened a new pull request, #9370:
URL: https://github.com/apache/opendal/pull/9370

   # Which issue does this PR close?
   
   Part of #9321 (tracker #9320).
   
   # Rationale for this change
   
   After `ListOptions` (#9332) and `StatOptions` (#9351), this PR generates the 
Python `DeleteOptions` from `core/core/src/types/options.rs` with the same 
generator, so its docs follow core. It exposes no new option: `if_none_match`, 
`if_version_match`, `if_version_not_match`, and `if_not_changed` stay unexposed.
   
   # What changes are included in this PR?
   
   - `GENERATED_OPTIONS` in `dev/src/generate/python.rs` adds `DeleteOptions` 
with the three keyword arguments Python has today: `version` 
(`Option<String>`), `recursive` (`Option<bool>`, `false` when omitted), and 
`if_match` (`Option<String>`). The table code paths and `options_rs.j2` are 
unchanged.
   - `bindings/python/src/options/generated.rs` now also holds `DeleteOptions`, 
and the hand-written copy in `options.rs` is gone. Ignoring doc comments, the 
generated code differs from main's in one place: `..Default::default()` became 
`if_none_match: None, if_version_match: None, if_version_not_match: None, 
if_not_changed: None`. `operator.rs` and `lib.rs` are unchanged: `delete` still 
builds core's `DeleteOptions` itself, and `presign_delete` builds this class.
   - The docstrings follow the `ListOptions` and `StatOptions` rules, plus one 
rule that core's struct doc needs. It names a kind without `ErrorKind::` ("also 
returns `Unsupported`"), so a code span that is exactly an `ErrorKind` variant 
with a Python exception now becomes that exception too: "also raises 
`opendal.exceptions.Unsupported`". `crate::NotFound`, unknown names, and other 
code spans stay as written. No `ListOptions` or `StatOptions` doc has such a 
span, so their output is unchanged.
   - New and extended tests in `dev/src/generate/python.rs`:
     - `DeleteOptions` field names, Rust types, extraction, conversion, and 
member order against literals copied from main. Each docstring must equal its 
core doc after the rendering rules, line for line in the pyclass doc comments 
too. The docs are checked for the capabilities and exceptions they name and for 
leftover Rust or core error-kind names.
     - `DeleteKwargs` keys and types; Python's `ast` reads back each docstring.
     - `delete` and `presign_delete` keyword arguments and defaults against 
main and against the table.
     - Core drift for `DeleteOptions` (missing field, kind changes, missing 
doc, skipped fields), new core fields rendering as defaults, a core reword that 
uses either markup or a bare kind, and the bare-kind rule.
   - `dev/src/generate/options.rs`: its test no longer expects `DeleteOptions` 
among the hand-written structs.
   
   # Are there any user-facing changes?
   
   Docstring text only, for `DeleteOptions` in `_opendal.pyi` and 
`DeleteKwargs` in `options.py`. Names, types, defaults, order, and behavior are 
unchanged.
   
   | Item | main | this PR (first line; later lines from core) |
   | --- | --- | --- |
   | `DeleteOptions` / `DeleteKwargs` | Options for `delete` operations. | 
Options for delete operations. Then how conditions combine, with 
`opendal.exceptions.ConditionNotMatch`, `Unsupported`, and `Conflict`, the 
missing-file no-op, and the conditional operation specification. |
   | `version` | The version of the file to delete. Only supported on 
version-aware backends. | Delete the given version of the file instead of the 
current one. Then that it is not a condition, and 
`op.capability().delete_with_version`. |
   | `recursive` | If True, delete the path recursively. Only supported on 
backends that support recursive delete. | Whether to delete the target 
recursively. Then the `false` default, trailing-slash scoping, and 
service-specific prefix matching. |
   | `if_match` | The ETag that the object must match before deletion. | Delete 
only when the file at the delete path has this exact ETag. Then 
`ConditionNotMatch` for a different ETag or a missing file, and `Unsupported` 
without `op.capability().delete_with_if_match`. |
   
   The `delete` and `presign_delete` parameter docs in `operator.rs` stay 
hand-written and unchanged. List items keep core's line breaks without 
indenting continuation lines, because the shared core doc parser trims each 
line; in Markdown those lines still continue the item.
   
   **Depends on #9363 for one sentence.** The struct doc still says "Once every 
condition holds, deleting a missing file remains a successful no-op." On memory 
and fs, `delete("missing", version="v1")` raises `Unsupported`, as the 
`Unsupported` item above that sentence says. #9363 rewords the shared core 
sentence to "With valid, supported options, deleting a missing file remains a 
successful no-op once every condition holds." This PR does not duplicate that 
core edit; after #9363 merges, this branch will merge main and regenerate the 
Python docs.
   
   Verification on `853c8ea8d`:
   
   - Doc claims, on a build of this branch, sync and async, on memory, fs, and 
versioned Silo S3 (61 checks):
     - Deleting a missing path without options or with `recursive=True` 
succeeds.
     - On memory and fs, `op.capability().delete_with_version` and 
`delete_with_if_match` are `False`, and `version` or `if_match` raises 
`opendal.exceptions.Unsupported` for an existing file and a missing path; the 
file stays.
     - On Silo, `if_match` with a different ETag raises `ConditionNotMatch` and 
keeps the file, a missing file raises `ConditionNotMatch`, and the file's ETag 
deletes it. `version` deletes only that version: the current content stays, and 
`stat(version=...)` of the deleted version raises `NotFound`.
     - `delete("a/", recursive=True)` removes `a/x` and `a/sub/y` and keeps 
`ab/z`. Without the trailing slash, `ab/z` is also removed on memory and Silo, 
but not on fs. Without `recursive`, `delete("d/")` keeps `d/x`.
     - Not reproduced: the `Conflict` item, and the item about a combination of 
conditions. Python exposes only `if_match` as a condition, and Silo accepts 
`version` together with `if_match`.
   - Against main, `options.py`, `_opendal.pyi`, and `operator.pyi` parse to 
identical Python ASTs once docstrings are removed. `operator.pyi`, 
`operator.rs`, and `lib.rs` are byte-identical.
   - An old-consumer probe gives the same 4026 lines on builds of main 
(`501c5d96f`) and this branch. Before comparing, S3 request IDs and dates are 
normalized, along with which key an S3 batch error names, which also varies 
between runs of main. The probe covers the `opendal._opendal.DeleteOptions` 
class and its missing constructor; the `__text_signature__` of every delete 
method; the `DeleteKwargs` keys, types, and totality; 2256 `delete` calls; and 
18 `presign_delete` calls. The `delete` calls are sync and async, on memory, 
fs, and Silo, against a file, a missing path, a directory, and a prefix. They 
pass every combination of 5 `version`, 6 `recursive`, and 3 `if_match` values 
(wrong types included), plus `if_none_match`, an unknown keyword, and 
all-`None`. The probe records each result or exception and the remaining files. 
For `presign_delete`, it records the S3 URL's method, path, and query keys, 
including `versionId`.
   - mypy `--strict` and pyright report the same three expected errors on a 
`DeleteKwargs` probe against the stubs from main and from this branch.
   - The memory suite gives 501 passed and 91 skipped, and the fs suite 550 
passed and 42 skipped, the same as the build of main.
   - `just stub-gen` (run twice), `just fmt`, `just lint`, `just test-typing`, 
`cargo check --features abi3`, and every `ci_odev.yml` generator plus `cargo 
fmt` leave `git diff --exit-code` clean, with hawkeye 7.2.0. The `examples` job 
steps pass, including the Sphinx build with `-W -n`. In an Ubuntu 24.04 
container, the dev tests (133), the Python generator check, the `lint` job 
steps, `test-typing`, the memory and fs suites (same counts as above), and the 
`examples` job steps pass. The stubs there regenerate identically apart from 
the license headers, which hawkeye, not installed in the container, adds in 
`just fmt`.
   - With core's `DeleteOptions` summary set to `"Options" for delete 
operations, with \d, \\ and """ inside.` in a scratch edit, `just stub-gen`, a 
second `just fmt`, and `just lint` exit 0. Python's `ast` reads that summary 
back from `DeleteKwargs` in `options.py` and from `DeleteOptions` in 
`_opendal.pyi`, and the runtime `__doc__` of both classes matches.
   - Scratch core edits through `generate -l python`: changing `recursive` to 
`usize` fails with `core DeleteOptions::recursive has kind Usize; Python 
DeleteOptions.recursive requires Bool`, and removing `if_match` fails too. 
Writing the `delete_with_version` link as a plain code span leaves the 
generated files byte-identical. Adding a core field adds only its default to 
the generated conversion. With `src/options/` moved aside, generation recreates 
it.
   - Mutations: 17 scratch edits each fail at least one test. They cover the 
table (dropping `if_match`, swapping `version` and `if_match`, `recursive` as 
`bool`, exposing `if_none_match`, `if_match` setting core `if_none_match`), 
`lowering` (an omitted flag as `true`), the bare-kind rule (off, or also 
mapping `crate::NotFound`), core naming the wrong capability for `if_match` or 
dropping the bare `Unsupported`, the docs (field docs saying `true` in 
`py_class` or in `options.py`, a class doc cut to its first paragraph, the 
template dropping a doc comment line), and `operator.rs` (`recursive=false` on 
`delete`, `recursive` added to `presign_delete`). A core reword saying 
`recursive` defaults to `true` passes, because the tests pin no core wording; 
the conversion (`unwrap_or(false)`) and signature (`recursive=None`) tests pin 
the default itself.
   
   # Breaking changes
   
   None.
   
   # AI Usage Statement
   
   - **Harness:** Claude Code via T3 Code. **Model:** Claude Opus 5.5. 
**Effort:** xhigh. **Role:** Implemented the generator change and tests; ran 
the doc-claim checks on memory, fs, and Silo S3, the surface diff, the probes, 
the mutation checks, and the local and Linux container CI steps; drafted this 
description. The author reviews every change and claim.
   


-- 
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