Skip to content

Structural method replacement can commit invalid indentation #16

Description

@isty2e

Environment

  • identedit 0.4.0

Reproduction

example.py:

class Example:
    def first(self) -> None:
        pass

    def target(self) -> None:
        pass

    def after(self) -> None:
        pass

replacement.py:

    def target(self) -> None:
        print("replacement")

Run:

identedit patch example.py \
  --symbol Example.target \
  --replace \
  --text-file replacement.py

identedit reports:

{
  "summary": {
    "files_modified": 1,
    "operations_applied": 1,
    "operations_failed": 0
  },
  "transaction": {
    "mode": "all_or_nothing",
    "status": "committed"
  }
}

The result is syntactically invalid:

class Example:
    def first(self) -> None:
        pass

        def target(self) -> None:
        print("replacement")

    def after(self) -> None:
        pass

python -m py_compile example.py raises IndentationError.

Expected

Either:

  1. normalize a method replacement snippet relative to the target container, or
  2. reject the indented snippet without modifying the file.

At minimum, structural patch application should parse-check the resulting file and roll back instead of reporting a committed all-or-nothing transaction for invalid syntax.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions