Clippy `ref_option` by ShaharNaveh · Pull Request #8122 · RustPython/RustPython
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: d9323494-8339-4bc7-81e4-3f874f65e3a0
📒 Files selected for processing (9)
Cargo.tomlcrates/derive-impl/src/compile_bytecode.rscrates/stdlib/src/socket.rscrates/vm/src/builtins/module.rscrates/vm/src/builtins/type.rscrates/vm/src/frame.rscrates/vm/src/getpath.rscrates/vm/src/import.rscrates/vm/src/stdlib/_ast/validate.rs
📝 Walkthrough
Walkthrough
Enables two Clippy lints (ref_option and mismatching_type_param_order) in the workspace configuration and applies the ref_option fix across nine files, converting &Option<T> function parameters to Option<&T> and updating all call sites with .as_ref() or .as_deref() conversions.
Changes
ref_option Clippy Lint Enablement and Application
| Layer / File(s) | Summary |
|---|---|
Enable workspace Clippy lints Cargo.toml |
Adds mismatching_type_param_order = "warn" and ref_option = "warn" to [workspace.lints.clippy]. |
get_spec_file_origin signature and callers crates/vm/src/import.rs, crates/vm/src/builtins/module.rs, crates/vm/src/frame.rs |
Changes spec parameter from &Option<PyObjectRef> to Option<&PyObjectRef> and updates all three call sites with .as_ref(). |
LocalsPlus::stack_index return type and frame callers crates/vm/src/frame.rs |
stack_index and stack_last return Option<&PyStackRef> instead of &Option<PyStackRef>; CopyItem uses .cloned() and WithExceptStart uses expect_unchecked with .clone().to_pyobj(). |
getpath.rs private helper signatures crates/vm/src/getpath.rs |
All five path helpers (detect_venv, detect_build_directory, calculate_prefix, calculate_exec_prefix, calculate_base_executable) take Option<&PathBuf> instead of &Option<PathBuf>, with init_path_config call sites using .as_ref(). |
Remaining fixes in socket, type, bytecode, and AST validate crates/stdlib/src/socket.rs, crates/vm/src/builtins/type.rs, crates/derive-impl/src/compile_bytecode.rs, crates/vm/src/stdlib/_ast/validate.rs |
Applies the same Option<&T> pattern to socket deadline passing, PyType::set_new/set_alloc base parameter, assert_source_empty, and validate_type_params with its three call sites. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
- RustPython/RustPython#7830: Also modifies
Cargo.toml's[workspace.lints.clippy]section to enable additional Clippy lints, the same configuration area this PR extends.
Suggested reviewers
- youknowone
🐇 A hop through the types, a
.as_ref()here,
No more&Option— the lints are clear!
From socket to getpath, from frame to the spec,
Option<&T>now keeps the borrow in check.
The warren is tidy, the clippy appeased,
This bunny of Rust is thoroughly pleased! 🎉
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The title 'Clippy ref_option' is vague and lacks context about what changes are being made to address this lint. |
Consider using a more descriptive title like 'Fix Clippy ref_option warnings across codebase' or 'Refactor Option parameters to Option<&T> patterns'. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 86.96% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.