Skip to content

Update ruff to 0.15.19, use it from crates.io#8160

Open
ShaharNaveh wants to merge 10 commits into
RustPython:mainfrom
ShaharNaveh:ruff-0-15-19
Open

Update ruff to 0.15.19, use it from crates.io#8160
ShaharNaveh wants to merge 10 commits into
RustPython:mainfrom
ShaharNaveh:ruff-0-15-19

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

astral-sh/ruff#26271

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened dictionary-comprehension handling to require optional keys be present, consistently across validation and code generation.
    • Improved formatted/debug string interpolation handling to correctly use leading/trailing debug text segments.
  • Refactor
    • Migrated multiple internal AST list-like containers (e.g., arguments, patterns, module bodies, defaults) to ThinVec.
    • Added ThinVec support to the AST conversion layer.
  • Chores
    • Updated automated dependency grouping rules and refreshed RustPython-patched Ruff workspace dependency declarations.
    • Added shared thin-vec workspace dependency.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Updates ruff workspace dependencies, adds thin-vec, migrates several AST container helpers to ThinVec, and adjusts codegen, unparse, validation, and string interpolation for optional dict-comprehension keys and DebugText accessors.

Changes

Ruff upgrade and ThinVec AST migration

Layer / File(s) Summary
Dependency updates
Cargo.toml, crates/vm/Cargo.toml, .github/dependabot.yml
Replaces the four ruff_* workspace deps with upstream 0.0.2 versions, adds thin-vec to the workspace and crates/vm, and adds a Dependabot ruff group.
ThinVec AST container migration
crates/vm/src/stdlib/_ast/node.rs, crates/vm/src/stdlib/_ast/argument.rs, crates/vm/src/stdlib/_ast/parameter.rs, crates/vm/src/stdlib/_ast/pattern.rs, crates/vm/src/stdlib/_ast/module.rs, crates/vm/src/stdlib/_ast/elif_else_clause.rs, crates/vm/src/stdlib/_ast.rs, crates/vm/src/stdlib/_ast/constant.rs, examples/parse_folder.rs
Adds Node support for ThinVec<T> and converts AST wrappers, merge/split helpers, docstring helpers, interactive module bodies, frozen-set keyword initialization, and parse-folder suite conversion to the new container style.
Dict-comprehension key handling
crates/codegen/src/compile.rs, crates/codegen/src/symboltable.rs, crates/codegen/src/unparse.rs, crates/vm/src/stdlib/_ast/validate.rs
Updates dict-comprehension and named-expression handling to unwrap optional keys with expect(...) before using the key expression.
DebugText accessor updates
crates/codegen/src/compile.rs, crates/codegen/src/unparse.rs, crates/vm/src/stdlib/_ast/string.rs
Switches DebugText reads to .leading() and .trailing() in code generation, unparse, and string interpolation paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • RustPython/RustPython#7789: Touches the same crates/vm/Cargo.toml dependency declarations by switching/adding workspace entries.

Suggested reviewers

  • youknowone

Poem

🐇 Hop, hop—new crates align,
ThinVec twirls through the AST vine.
Keys unwrapped and debug text sings,
RustPython hums on cleaner springs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: upgrading Ruff to 0.15.19 and switching the source to crates.io.
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.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] test: cpython/Lib/test/test_patma.py (TODO: 13)

dependencies:

dependent tests: (no tests depend on patma)

[x] test: cpython/Lib/test/test_unpack.py
[ ] test: cpython/Lib/test/test_unpack_ex.py (TODO: 6)

dependencies:

dependent tests: (no tests depend on unpack)

[ ] test: cpython/Lib/test/test_syntax.py (TODO: 210)

dependencies:

dependent tests: (no tests depend on syntax)

[ ] test: cpython/Lib/test/test_grammar.py (TODO: 11)

dependencies:

dependent tests: (no tests depend on grammar)

[x] test: cpython/Lib/test/test_compile.py (TODO: 11)
[x] test: cpython/Lib/test/test_compiler_assemble.py
[x] test: cpython/Lib/test/test_compiler_codegen.py
[x] test: cpython/Lib/test/test_peepholer.py (TODO: 4)

dependencies:

dependent tests: (no tests depend on compile)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/codegen/src/compile.rs (1)

8271-8283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract key once and reuse it in this dict-comp path.

key.as_ref().expect(...) is repeated several times in the same flow. Bind it once and reuse it for compile/await/range operations.

Proposed refactor
+                    let key = key
+                        .as_ref()
+                        .expect("RustPython does not support PEP798 yet");
                     generators,
                     &|compiler, collection_add_i| {
                         // changed evaluation order for Py38 named expression PEP 572
-                        compiler.compile_expression(
-                            &key.as_ref()
-                                .expect("RustPython does not support PEP798 yet"),
-                        )?;
+                        compiler.compile_expression(key)?;
                         compiler.compile_expression(value)?;
 
                         compiler.set_source_range(TextRange::new(
-                            key.as_ref()
-                                .expect("RustPython does not support PEP798 yet")
-                                .range()
-                                .start(),
+                            key.range().start(),
                             value.range().end(),
                         ));
@@
-                    Self::contains_await(
-                        &key.as_ref()
-                            .expect("RustPython does not support PEP798 yet"),
-                    ) || Self::contains_await(value)
+                    Self::contains_await(key) || Self::contains_await(value)
                         || Self::generators_contain_await(generators),
                     *range,
                     TextRange::new(
-                        key.as_ref()
-                            .expect("RustPython does not support PEP798 yet")
-                            .range()
-                            .start(),
+                        key.range().start(),
                         value.range().end(),
                     ),
-                    key.as_ref()
-                        .expect("RustPython does not support PEP798 yet")
-                        .range(),
+                    key.range(),
                 )?;

As per coding guidelines, when logic is shared, extract the differing value first and call the common logic once to avoid duplication.

Also applies to: 8294-8309

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/codegen/src/compile.rs` around lines 8271 - 8283, The dict-comp
handling in compile.rs repeats key.as_ref().expect(...) multiple times; extract
that value once in the affected flow and reuse it for compile_expression, any
await handling, and source-range calculation. Update the dict-comp path around
the existing compiler.compile_expression and compiler.set_source_range calls,
and apply the same refactor to the other referenced block so the shared logic
uses a single bound key value instead of duplicated expectations.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/codegen/src/unparse.rs`:
- Around line 256-260: The call in unparse_expr for the key handling path has a
redundant leading borrow that triggers a needless_borrow warning. Update the
expression in unparse.rs around the self.unparse_expr call so it passes the
reference returned by key.as_ref().expect("RustPython does not support PEP798
yet") directly, without adding an extra &.

---

Nitpick comments:
In `@crates/codegen/src/compile.rs`:
- Around line 8271-8283: The dict-comp handling in compile.rs repeats
key.as_ref().expect(...) multiple times; extract that value once in the affected
flow and reuse it for compile_expression, any await handling, and source-range
calculation. Update the dict-comp path around the existing
compiler.compile_expression and compiler.set_source_range calls, and apply the
same refactor to the other referenced block so the shared logic uses a single
bound key value instead of duplicated expectations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: e4cf7347-2742-4018-9f90-8b6b99d09026

📥 Commits

Reviewing files that changed from the base of the PR and between 39a2fda and a0690de.

⛔ Files ignored due to path filters (3)
  • Cargo.lock is excluded by !**/*.lock
  • Lib/test/test_grammar.py is excluded by !Lib/**
  • Lib/test/test_syntax.py is excluded by !Lib/**
📒 Files selected for processing (16)
  • .github/dependabot.yml
  • Cargo.toml
  • crates/codegen/src/compile.rs
  • crates/codegen/src/symboltable.rs
  • crates/codegen/src/unparse.rs
  • crates/vm/Cargo.toml
  • crates/vm/src/stdlib/_ast.rs
  • crates/vm/src/stdlib/_ast/argument.rs
  • crates/vm/src/stdlib/_ast/constant.rs
  • crates/vm/src/stdlib/_ast/elif_else_clause.rs
  • crates/vm/src/stdlib/_ast/module.rs
  • crates/vm/src/stdlib/_ast/node.rs
  • crates/vm/src/stdlib/_ast/parameter.rs
  • crates/vm/src/stdlib/_ast/pattern.rs
  • crates/vm/src/stdlib/_ast/string.rs
  • crates/vm/src/stdlib/_ast/validate.rs

Comment thread crates/codegen/src/unparse.rs
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