Update ruff to 0.15.19, use it from crates.io by ShaharNaveh · Pull Request #8160 · RustPython/RustPython · GitHub
Skip to content

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

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

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

@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
@youknowone

Copy link
Copy Markdown
Member

I need patched version of ruff in #8138
could you check if we can reasonably avoid this patch? RustPython/ruff#2

@ShaharNaveh

Copy link
Copy Markdown
Contributor Author

I need patched version of ruff in #8138 could you check if we can reasonably avoid this patch? RustPython/ruff#2

I believe I could give a better answer after #8138 is merged. making this a draft for now

@ShaharNaveh ShaharNaveh marked this pull request as draft June 26, 2026 06:40
@ShaharNaveh

Copy link
Copy Markdown
Contributor Author

I need patched version of ruff in #8138 could you check if we can reasonably avoid this patch? RustPython/ruff#2

Looking at it agian, it looks like we only add new fields to the AST structs but we don't really use them over at ruff side. wouldn't it be more sustainable for us to do:

// In the RustPython crate, not in ruff

pub struct StmtDelete {
    inner: ruff_python_ast::StmtDelete,
    runtime_targets: Option<Vec<Option<crate::Expr>>>,
}

we can add a clippy rule for disallowed_types to make sure we use our type only.


I'm not so sure why is that patch needed anyways?how does cpython handle it? does they add those fields as well?

@youknowone

Copy link
Copy Markdown
Member

cpython parser is more friendly to python runtime. ruff parser is more optimzied for ruff purpose.
my first approach was similar to your seggestion, but it easily grew too verbose.
that was not a conclusion. could you try that if it makes reasonable local patch? obviously I prefer NOT to patch ruff ourselves for easire maintanence. but at the same time, if we have to add too much complexity just to avoid patch, that's not good.

@ShaharNaveh

Copy link
Copy Markdown
Contributor Author

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.

2 participants