Commit 1f43a61
committed
fix(patch): make --apply safe on descriptors, fallbacks and backups
Follow-up to the AST patcher, addressing review findings.
Correctness:
- _wrap_pytest_test captured the target with getattr, which unwraps a
staticmethod/classmethod. Every verification of such a method raised
TypeError, and "restoring" it left the class permanently mis-bound.
Capture with inspect.getattr_static and re-wrap the candidate.
- Validate the spliced result on the textual fallback path too, not just
the AST path. When the file was already unparseable the replacement is
checked on its own, so a repair to a broken file is still possible.
- Re-indent the replacement in _textual_replace; a repair dedented to
column 0 used to corrupt the enclosing block.
- Refuse a textual match that occurs more than once instead of patching
the first one.
- Never overwrite an existing .heal-backup; later runs get a numbered
suffix so the pristine copy survives.
- Preserve the file's line endings instead of round-tripping them
through read_text/write_text.
- Take only the repaired function's own lines, and refuse a repair that
defines anything alongside it: splicing put those in the target's
scope, dropping them left a NameError at call time.
- Keep a missing trailing newline missing.
Reporting:
- apply_function_patch returns PatchResult(src_path, backup_path, notes)
so "no backup written" cannot read as a backup filename, and keeping
decorators the repair omitted is reported rather than silent.
- Warn instead of swallowing failures to restore a patched reference or
to scan a module for aliases.
Tests: 17 new, covering descriptor re-wrap and subclass cls binding, the
changed-decorator branch, closures via outer.inner, dotted misses, backup
versioning, fallback re-indent/ambiguity/validation, CRLF round trip and
trailing newlines. Both xfail markers are fixed and removed.
The old fallback test used `this is not python` as its "unparseable"
fixture, which parses fine as an `is not` comparison, so the fallback
path had never actually run.1 parent 0c9b7c0 commit 1f43a61
7 files changed
Lines changed: 1120 additions & 130 deletions
File tree
- site/app
- src/self_heal
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
0 commit comments