chitralverma opened a new issue, #9321: URL: https://github.com/apache/opendal/issues/9321
*Drafted with AI assistance (Claude Code, Claude Opus 5.5, effort xhigh); the author is accountable for it.* ### Feature Description Generate the Python binding's operation options from core, then expose the options Python lacks. Part of #9320. Abbreviations: VM/VNM = `if_version_match`/`if_version_not_match`, INC = `if_not_changed`. Links point at `4ae8e61222`. ### Problem and Solution **Current code** - [`bindings/python/src/options.rs`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/bindings/python/src/options.rs) defines `ReadOptions` (L36), `WriteOptions` (L251), `ListOptions` (L376), `StatOptions` (L421), `CopyOptions` (L482), `RenameOptions` (L499), and `DeleteOptions` (L515) by hand. Alongside them it holds the `FromPyObject` impls, the kwarg allowlists `OPEN_READ_OPTION_KEYS` (L91), `READ_OPTION_KEYS` (L105), and `WRITE_OPTION_KEYS` (L122), and the conversions to core. There is no Python `ReaderOptions`: `From<ReadOptions> for ReaderOptions` (L331) builds it. - [`bindings/python/src/operator.rs`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/bindings/python/src/operator.rs) repeats each option as a keyword-only argument in every `#[pyo3(signature)]`. The sync methods are `read` (L665), `write` (L780), `stat` (L863), `copy` (L915), `rename` (L946), `delete` (L1022), `list` (L1115), and `scan` (L1172). The async methods and `presign_*` (L2210–L2417) repeat them again. - [`dev/src/generate/options.rs`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/dev/src/generate/options.rs) parses the binding's own `options.rs`, not core, to render the `options.py` TypedDicts ([`generate_options_py`, python.rs#L641](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/dev/src/generate/python.rs#L641)). - [`lib.rs#L141-L143`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/bindings/python/src/lib.rs#L141-L143) exports `DeleteOptions`, `ListOptions`, `ReadOptions`, `StatOptions`, and `WriteOptions` on `opendal` as opaque classes, which `_opendal.pyi` declares. **Missing options** - read: VM, VNM, `limit`, `content_length_hint`, suffix ranges (`offset`/`size` only select forward ranges), and `checksum` - reader (`open` in read mode): VM, VNM, `content_length_hint`, and `checksum` - stat: VM, VNM, and `checksum` - write: `content_language`, `expires`, VM, VNM, and INC. `checksum` accepts only an algorithm name (#9316). - list: `glob` - delete: `if_none_match`, VM, VNM, and INC - copy: every field except `if_not_exists` - compose, restore, deleter: no API **Step 1: generate the existing options with no API change** - Add a table in `dev/src/generate/python.rs` that maps each core field to the existing Python kwarg name, type, and default. Examples: `range` maps to `offset`/`size`; `override_*` maps to `content_type`/`cache_control`/`content_disposition`; `Option<bool>` flags convert with `unwrap_or(false)`; `concurrent` converts with `unwrap_or_default()`. The table marks every other core field as not exposed. - Render `options.rs` (structs, `FromPyObject`, allowlists, conversions) and `options.py` from that table, and retire `dev/src/generate/options.rs`. Move its `doc_lines` helper (L166) to a shared module; `capability.rs` (L30), `metadata.rs` (L33), and `core_options.rs` (L31) import it. - Keep the hand-written `checksum: ChecksumAlgorithm` write kwarg as an override. The parser skips `WriteOptions::checksum` ([core_options.rs#L106](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/dev/src/generate/core_options.rs#L106)), and #9316 tracks how it converges. - Generate Rust mirrors and core conversions for `ComposeOptions`, `ComposeSourceOptions`, `RestoreOptions`, and `DeleterOptions`. Keep them out of the module exports and `options.py` until step 2 adds the methods. - Either generate the operator signatures or add a generator test that each signature lists exactly the table's exposed fields. Step 2 edits about twenty signatures. Behavior that step 1 must preserve: - Kwarg names, accepted types, defaults, and errors, including `TypeError("Unable to convert key: ...")` and `open() got an unexpected keyword argument`. - `open()` allowlists: read mode rejects `content_type`, `cache_control`, and `content_disposition` unless they are `None`, and write mode rejects read-only keys unless they are `None` (`reject_unknown_kwargs`, L137). - `prefetch` combined with header overrides raises `ValueError` (`use_prefetch_reader`, L219). - The export list: exactly the five classes in `lib.rs#L143`. `CopyOptions` and `RenameOptions` stay unexported. - `options.py` and the `just stub-gen` output stay byte-identical. The `stubs` job in `ci_bindings_python.yml` diffs both. Add a frozen-surface test whose expectations are literals copied from `main`: the allowlists, each method's kwargs, and each `options.py` class and its fields. Prove it with a mutation. **Step 2: expose the missing options** - Add the missing kwargs. They are keyword-only, so adding them does not break callers. - Read `limit`: `presign_read` takes the same `ReadOptions` (L2315), so document the `ConfigInvalid` conflicts with a positive `chunk`, with `concurrent` greater than one, and with presign. `open()` builds `ReaderOptions`, which has no `limit`, so reject `limit` in read mode instead of dropping it. .NET and Java #9234 already do this. - Suffix ranges: agree on a kwarg, because `offset`/`size` cannot express one. - INC: accept a `Metadata` from `stat`. Core lowers it to a version or a non-weak ETag. - `expires`: agree on the Python type. - Compose, restore, and deleter: add the methods and wire the step-1 mirrors. Compose needs an input shape for per-source options. - Blocked by #9319: write-side VM, VNM, and INC, plus compose `if_version_match` and `if_not_changed`. Copy conditions are not blocked: GCS does not advertise `copy_with_if_not_exists`, so the copy request builder never receives the combination that #9319 covers. The `checksum` fields follow #9316. ### Additional Context Step 1 is not a release-impacting change. Step 2 is additive. ### Are you willing to contribute to the development of this feature? - [x] Yes, I am willing to contribute to the development of this feature. -- 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]
