land: python-indent-edits

Merged
AF
2d ago
+2424-101

Accepted agent delivery; branch-keyed search descriptor included.


Summary by cubic

Stops Python edits from leaving an IndentationError while reporting success, and makes whitespace-insensitive matches land at the file's indentation instead of writing misplaced lines.

Bug Fixes

  • validate_on_edit: syntax now also checks Python block indentation the way CPython's tokenizer does (tab stops at 8 and tabs as 1, both must agree), so edits that produce "unexpected indent", "unindent does not match any outer indentation level", "expected an indented block", or a TabError are rolled back and created files report the error line.
  • A loose match (fuzzy passes 3 and 4) now measures the indentation difference and shifts every replacement line by it; before, only the first line followed the file's indentation.

New Features

  • When indentation is ambiguous — tabs against spaces, different offsets on different lines, a blank first line, or a too-deep oldString whose replacement dedents past the extra depth — the edit fails with the new ambiguous_indentation code and leaves the file untouched, in any language.
  • Edit replies now include a one-line notice describing what the loose match ignored and whether newString was re-indented, deduplicated across identical matches in the Rust and bridge formatters.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issue was identified.

Summary

Adds Python indentation checks and shifts loose-match replacements to the file’s indentation.

  • Loose edits keep every replacement line at the file’s indentation.
  • Python edits now check block indentation as well as syntax.
  • Inlined function bodies fit the call site without changing string text.

No new actionable issues were identified. The current code addresses the five supplied, unnumbered previous findings.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Find text] --> B{Indentation differs?}
    B -->|No| E[Build edit]
    B -->|Yes| C[Find string contents once]
    C --> D[Shift code lines only]
    D --> E
    E --> F[Write and check syntax]
    F --> G{Previously valid file becomes invalid?}
    G -->|Yes| H[Restore original file]
    G -->|No| I[Return edit result]

Reviews (5) · Last reviewed commit: "Pass the launch policy in the rebased Py..." · Reviewed by Greptile