Clippy nursery lints by ShaharNaveh · Pull Request #7875 · RustPython/RustPython
Note
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
-
▶️ Resume reviews - 🔍 Trigger review
📝 Walkthrough
Walkthrough
This PR replaces explicit concrete type names with Self across the codebase, adds Eq derives to many types, reorganizes workspace Clippy lint groups in Cargo.toml, and applies small expression refactors and constant-folding/formatting adjustments.
Changes
Clippy Lint Configuration and Equality Derivations
| Layer / File(s) | Summary |
|---|---|
Clippy Lint Configuration Cargo.toml |
Reorganizes [workspace.lints.clippy] warn section into logical groups (restriction, nursery, pedantic) and adds several nursery-level lints including use_self, derive_partial_eq_without_eq, imprecise_flops, and others for gradual enforcement. |
Equality Trait Derivations crates/common/src/cformat.rs, crates/common/src/format.rs, crates/compiler-core/src/bytecode.rs, crates/vm/src/function/method.rs, crates/vm/src/stdlib/posix.rs |
Adds Eq trait to 20+ public enums and structs that already derive PartialEq, enabling stricter compile-time equality checks across formatting, bytecode, and metadata types. |
Systematic Self-Type Refactoring
| Layer / File(s) | Summary |
|---|---|
Object Core and GC System crates/vm/src/object/core.rs |
Updates GC traversal, weakref handling, and type-safe pointer casting to use Self for generic type parameters; changes PyWeak::pointers type, weakref stripe lock keying, gc_get_referent_ptrs return type, and gc_clear_raw signature. |
VM Frame and Display Implementations crates/vm/src/frame.rs, crates/vm/src/object/ext.rs, crates/vm/src/datastack.rs, crates/vm/src/vm/context.rs |
Updates frame pointer return types, inline display trait bounds, linked-list pointer types, and context initialization to use Self consistently. |
Builtin Types Refactoring crates/vm/src/builtins/bytes.rs, crates/vm/src/builtins/code.rs, crates/vm/src/builtins/str.rs, crates/vm/src/builtins/tuple.rs, crates/vm/src/builtins/type.rs, and others |
Systematically replaces explicit type names with Self in constructors, downcasts, method implementations, and signature parameters across builtin types. |
Stdlib Modules Refactoring crates/stdlib/src/_asyncio.rs, crates/stdlib/src/ssl.rs, crates/stdlib/src/_io.rs, crates/stdlib/src/_functools.rs, and others |
Updates stdlib modules to use Self in constructors, downcasts, and method dispatches in finalizers, trait implementations, and FFI helpers for consistency. |
Ctypes Foreign Function Interface crates/vm/src/stdlib/_ctypes/array.rs, crates/vm/src/stdlib/_ctypes/base.rs, crates/vm/src/stdlib/_ctypes/function.rs, and others |
Refactors ctypes implementation to use Self for recursive method calls, struct construction, and type downcasting in field descriptors and type conversions. |
Compiler and Code Generation crates/codegen/src/compile.rs, crates/compiler-core/src/bytecode.rs, crates/vm/src/stdlib/_ast/constant.rs, and others |
Updates compiler layers and AST handling to use Self in pattern matching, struct construction, enum variants, and recursive type references. |
Expression Refactoring and Logic Enhancements
| Layer / File(s) | Summary |
|---|---|
Statement to Expression Refactoring crates/stdlib/src/statistics.rs, crates/vm/src/vm/vm_object.rs, crates/vm/src/vm/vm_ops.rs |
Converts mutable variable assignments with conditional blocks into direct conditional expressions while preserving behavior. |
Complex Arithmetic and Slot Function Expansion crates/codegen/src/ir.rs, crates/vm/src/builtins/descriptor.rs, crates/vm/src/builtins/union.rs, and others |
Expands SlotFunc::call to explicitly handle descriptor, sequence, mapping, and number slot variants; preserves complex number signed-zero behavior; simplifies union getitem logic. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- RustPython/RustPython#7755: Also modifies
Cargo.tomlClippy lint configuration; related lint reorganization. - RustPython/RustPython#7830: Related edits to root
Cargo.tomlClippywarnentries. - RustPython/RustPython#7541: Changes to codegen constant detection logic overlap with
crates/codegen/src/compile.rsedits.
Suggested reviewers
- youknowone
- coolreader18
- fanninpm
"🐰 I hopped through code and changed each name,
Self now stands where types were once the same.
Eq joins PartialEq, lints are neatly lined,
A tidy burrow of types — happy, refined! 🥕"
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests