Skip to content

Clippy ref_option#8122

Open
ShaharNaveh wants to merge 1 commit into
RustPython:mainfrom
ShaharNaveh:clippy-rules-2
Open

Clippy ref_option#8122
ShaharNaveh wants to merge 1 commit into
RustPython:mainfrom
ShaharNaveh:clippy-rules-2

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Summary by CodeRabbit

  • Refactor

    • Internal code improvements standardizing patterns across core modules including frame management, type definitions, module loading, and path configuration. Changes enhance code consistency and reduce technical debt while maintaining existing functionality.
  • Chores

    • Added enhanced linting rules to maintain code quality standards.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

📥 Commits

Reviewing files that changed from the base of the PR and between 08a1d6f and 3ba6608.

📒 Files selected for processing (9)
  • Cargo.toml
  • crates/derive-impl/src/compile_bytecode.rs
  • crates/stdlib/src/socket.rs
  • crates/vm/src/builtins/module.rs
  • crates/vm/src/builtins/type.rs
  • crates/vm/src/frame.rs
  • crates/vm/src/getpath.rs
  • crates/vm/src/import.rs
  • crates/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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant