Skip to content

Commit 35d5ed3

Browse files
before_recipe hooks fix (#6735)
1 parent fbc7c41 commit 35d5ed3

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

rewrite-python/rewrite/src/rewrite/test/rewrite_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def rewrite_run(self, *source_specs: SourceSpec) -> None:
178178
self._expect_parse_print_idempotence(parsed)
179179
all_parsed.extend(parsed)
180180

181+
# Apply before_recipe hooks (after idempotence check, before recipe execution)
182+
all_parsed = [
183+
(spec, spec.before_recipe(sf) or sf) if spec.before_recipe else (spec, sf)
184+
for spec, sf in all_parsed
185+
]
186+
181187
# Run the recipe
182188
source_files = [sf for _, sf in all_parsed]
183189
lss = InMemoryLargeSourceSet(source_files)
@@ -221,12 +227,6 @@ def _parse(self, specs: List[SourceSpec]) -> List[Tuple[SourceSpec, SourceFile]]
221227
source = dedent(spec.before)
222228
parsed = self._parse_python(source, source_path)
223229

224-
# Call before_recipe hook if provided
225-
if spec.before_recipe:
226-
modified = spec.before_recipe(parsed)
227-
if modified is not None:
228-
parsed = modified
229-
230230
result.append((spec, parsed))
231231

232232
return result

rewrite-python/rewrite/tests/test_rewrite_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def after_hook(cu: CompilationUnit) -> None:
216216
assert len(called) == 1
217217
assert called[0][0] == "after"
218218

219-
@pytest.mark.skip(reason="The test has been failing for unknown reason, disabling on 2026-02-10")
220219
def test_before_recipe_can_modify_ast(self):
221220
"""Test that before_recipe can modify the parsed AST."""
222221
from rewrite import random_id

0 commit comments

Comments
 (0)