◐ Shell
clean mode source ↗

Update ruff 0.14.1 by ShaharNaveh · Pull Request #6195 · RustPython/RustPython

Walkthrough

This PR updates ruff-related dependencies and adapts the codebase to ruff's revised AST and source-location shapes: adding node_index to many AST nodes, renaming row/columnline/character_offset, switching to PositionEncoding::Utf8, and replacing FString types with InterpolatedString types (plus initial t-string scaffolding).

Changes

Cohort / File(s) Summary
Dependency update
Cargo.toml
Bumped ruff-related git tags from 0.11.00.14.1.
Codegen — compile & IR
compiler/codegen/src/compile.rs, compiler/codegen/src/ir.rs, compiler/codegen/src/lib.rs
Added duplicate-parameter validation hook; switched location encoding to PositionEncoding::Utf8; adapted source-location field access (rowline, columncharacter_offset); migrated FString → InterpolatedString representations; added TString name mapping/scaffold.
Codegen — symboltable & unparse
compiler/codegen/src/symboltable.rs, compiler/codegen/src/unparse.rs
Pattern matches updated to include new node_index fields; unparse now consumes ruff::InterpolatedStringElement and InterpolatedStringFormatSpec; added TString unparsing scaffold.
Compiler core & marshal
compiler/core/src/lib.rs, compiler/core/src/marshal.rs, compiler/src/lib.rs
Re-exported PositionEncoding; serialized/deserialized SourceLocation fields renamed to line/character_offset; CompileError::location made const; parse errors use Utf8 encoding.
Bytecode / disassembly
compiler/core/src/bytecode.rs
Adjusted formatting digit calculations and use of line for disassembly output.
VM frame, traceback & faulthandler
vm/src/frame.rs, vm/src/builtins/frame.rs, stdlib/src/faulthandler.rs
Use line/character_offset for frame/traceback/faulthandler; avoid unnecessary SourceLocation clones (rely on Copy semantics).
VM AST glue — many files
vm/src/stdlib/ast.rs, vm/src/stdlib/ast/* (expression.rs, statement.rs, parameter.rs, pattern.rs, string.rs, module.rs, constant.rs, argument.rs, other.rs, type_parameters.rs, elif_else_clause.rs, exception.rs)
Added and threaded node_index across ~30+ AST node types; updated (de)serialization/conversion paths; replaced FString flows with InterpolatedString flows; inserted placeholders for TString where applicable.
String interpolation & lexer errors
vm/src/stdlib/ast/string.rs, src/shell.rs, vm/src/vm/vm_new.rs
Reworked f-string handling to InterpolatedStringElement variants (including node_index); switched lexical error variant to InterpolatedStringErrorType::UnterminatedTripleQuotedString.
WASM & JS error mapping
wasm/lib/src/convert.rs
Map compile error locations to JS using line and character_offset fields.

Sequence Diagram(s)

sequenceDiagram
    participant Parser as Ruff Parser (new AST)
    participant Compiler as Compiler / Codegen
    participant VM as VM / Runtime

    Note over Parser,Compiler: AST shape changes: node_index, InterpolatedString, SourceLocation(line+char_off)
    Parser->>Compiler: provide AST nodes (with node_index, ranges)
    Compiler->>Compiler: validate duplicate params
    Compiler->>Compiler: convert/interpolate strings (detect await inside interpolations)
    Compiler->>Compiler: compute source locations using PositionEncoding::Utf8
    Compiler->>VM: emit bytecode + linetable entries (line, character_offset)
    VM->>VM: build tracebacks and frame info using .line/.character_offset
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • arihant2math

Poem

🐰 I hopped through nodes with tiny feet,

Gave every node an index neat,
Strings now sparkle, braces sing,
Row became line in UTF‑8 spring,
A rabbit cheers—code leaps to meet! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Update ruff 0.14.1" accurately describes the primary objective of this pull request, which is to upgrade the ruff dependency from version 0.11.0 to 0.14.1. While the changeset includes extensive refactoring related to AST changes (node_index fields), string interpolation types, source location field renames, and duplicated-parameter validation, these are consequences of the version upgrade rather than independent changes. The title is clear, specific, and sufficiently conveys the main change to a developer scanning the repository history.
Linked Issues Check ✅ Passed The PR successfully addresses the coding requirements from both linked issues. Issue #6170 and #6177 both target ruff version upgrades (toward >=0.13.1), and this PR achieves that by updating to ruff 0.14.1. The PR handles all the major AST-related changes including: addition of node_index fields across numerous AST node types (ExprNamed, ExprDict, ExprAwait, StmtFunctionDef, etc.), refactoring string interpolation from FString types to InterpolatedStringElements, adding preliminary t-string support, implementing source location field renames (row → line, column → character_offset), using PositionEncoding::Utf8, exporting PositionEncoding publicly, and adding compile-time validation for duplicate parameters. The changes comprehensively address the objectives outlined in the linked issues.
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly related to the ruff 0.14.1 upgrade and its associated API changes. The modifications span Cargo.toml (dependency versions), compiler modules (AST handling and codegen), VM and stdlib components (AST field propagation), and WASM utilities (error location mapping)—all addressing the structural changes introduced by the ruff upgrade. There are no unrelated refactorings, unrelated feature additions, or changes outside the scope of adapting the codebase to the new ruff version and its AST structure modifications.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.