Update to ruff 0.13.1 by coolreader18 · Pull Request #6177 · RustPython/RustPython
Walkthrough
Updates dependencies and migrates string interpolation from FString to InterpolatedString types, introduces TString handling, and propagates a new node_index across AST structures. Adopts UTF-8 position encoding and renames SourceLocation fields to line/character_offset. Adjusts linetable, bytecode formatting, error mapping, and multiple VM/stdlib paths to the new location and interpolation APIs.
Changes
| Cohort / File(s) | Summary |
|---|---|
Dependencies (ruff crates bump)Cargo.toml |
Bumps ruff_python_{parser,ast}, ruff_text_size, ruff_source_file from tag 0.11.0 to 0.13.1. |
PositionEncoding + SourceLocation fieldscompiler/codegen/src/compile.rs, compiler/codegen/src/ir.rs, compiler/codegen/src/symboltable.rs,compiler/core/src/lib.rs, compiler/core/src/marshal.rs, compiler/core/src/bytecode.rs,compiler/src/lib.rs, stdlib/src/faulthandler.rs, vm/src/builtins/frame.rs, vm/src/frame.rs,vm/src/stdlib/ast.rs, vm/src/vm/vm_new.rs, wasm/lib/src/convert.rs |
Switch to PositionEncoding::Utf8 and rename SourceLocation fields row/column → line/character_offset; update linetable math, error reporting, and conversions accordingly. |
Interpolated string model + TStringcompiler/codegen/src/compile.rs, compiler/codegen/src/lib.rs, compiler/codegen/src/unparse.rs,src/shell.rs, vm/src/stdlib/ast/string.rs, vm/src/vm/vm_new.rs |
Replace FString* with InterpolatedString* types, add TString arm in name/unparse paths, update error enum to InterpolatedStringErrorType, and rework f-string conversions. |
AST node_index propagationcompiler/codegen/src/compile.rs, vm/src/stdlib/ast/* (e.g., expression.rs, statement.rs, pattern.rs, parameter.rs, constant.rs, module.rs, other.rs, elif_else_clause.rs, exception.rs, argument.rs, type_parameters.rs) |
Add/propagate node_index across many AST node structs; update constructors/destructuring to set Default::default() or ignore with _. |
Linetable and bytecode formatting tweakscompiler/codegen/src/ir.rs, compiler/core/src/bytecode.rs |
Align line/column usage with new fields; adjust digit calculations and indexing (line.digits, to_zero_indexed). |
CompileError API adjustmentscompiler/src/lib.rs |
Use PositionEncoding::Utf8 for parse errors; make location() and python_location() const; simplify location handling (no cloning). |
Core re-exportscompiler/core/src/lib.rs |
Re-exports PositionEncoding alongside existing ruff_source_file types. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant U as User Code
participant P as Parser
participant AST as AST (ruff)
participant ST as SymbolTable
participant CG as Codegen
participant VM as VM
U->>P: Source text
P->>AST: Build nodes (InterpolatedString / TString)
AST->>ST: Scope analysis (UTF-8 locations)
ST-->>AST: Symbols, errors (line/character_offset)
AST->>CG: Emit IR/bytecode (iterate InterpolatedStringElements)
CG-->>VM: CodeObject + linetable (UTF-8 indexed)
Note over CG,VM: Locations use line + character_offset
sequenceDiagram
autonumber
participant Err as Error (Parse/Codegen)
participant SF as SourceFile
participant M as Mappers
participant Out as Consumers (VM/WASM/Stdlib)
Err->>SF: to_source_code()
SF->>M: source_location(range, PositionEncoding::Utf8)
M-->>Out: SourceLocation{ line, character_offset }
Out->>Out: Display/traceback/JS mapping
Note over M,Out: row/column replaced with line/character_offset
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- code object linetable #6150 — Also changes code-object linetable and location handling; overlaps with this PR’s linetable/source-location updates.
- Export
ruff_source_filetypes inrustpython_compiler_core#6020 — Introduces/exports ruff_source_file types; directly related to adding PositionEncoding re-exports here. - Replace
compiler::sourcemodule withruff_source_file#6016 — Prior migration of source types and location fields; aligns with row/column → line/character_offset changes.
Suggested reviewers
- youknowone
- arihant2math
Poem
A rabbit taps keys with a twinkle of light,
UTF-8 footsteps hop lineward through night.
F-strings transformed, new threads intertwine,
node_index burrows in every vine.
Errors now point where the carrots align—
Compile on! The garden looks fine. 🥕✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 5.74% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title “Update to ruff 0.13.1” succinctly summarizes the primary change of the pull request, which is bumping the ruff dependencies to version 0.13.1 and aligning code with the new API; it directly reflects the main developer intent without extraneous detail. |
✨ Finishing touches
- 📝 Generate Docstrings
🧪 Generate unit tests
- Create PR with unit tests
- Post copyable unit tests in a comment
Tip
👮 Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
- Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
- Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.
Please see the documentation for more information.
Example:
reviews: pre_merge_checks: custom_checks: - name: "Undocumented Breaking Changes" mode: "warning" instructions: | Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).
Please share your feedback with us on this Discord post.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.