Whole file

MarcoGorelli/auto-walrus

The author described this change as Fix incorrect rewrite with --unsafe on nested functions. It counts as a record because the check below fails on the code as it stood at d1f1f71b6 and passes on c9fe67303, with nothing else changed between the two runs.

Fix saved2026-02-02
Sharing licenceMIT · LICENSE
Change size+3 3

What the code was meant to do, written into the code itself as a save note

Fix incorrect rewrite with --unsafe on nested functions

The change

271271 except SyntaxError: # pragma: no cover
272272 return None
273273
274- walruses = []
274+ walrus_set: set[tuple[Token, Token]] = set()
275275 for node in ast.walk(tree):
276276 if isinstance(node, ast.FunctionDef):
277- walruses.extend(visit_function_def(node, config))
277+ walrus_set.update(visit_function_def(node, config))
278278 lines_to_remove = []
279- walruses = sorted(walruses, key=lambda x: (-x[1][1], -x[1][2]))
279+ walruses = sorted(walrus_set, key=lambda x: (-x[1][1], -x[1][2]))
280280
281281 if not walruses:
282282 return None

The check that tells the two apart

failpass·tests/main_test.py::test_rewrite_unsafe[def

Check file tests/main_test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itd1f1f71b6e68e70cd0edaa073814bf5186e540f8
Broken version dated2026-02-02
Moduleauto_walrus
Units changedauto_walrus
Fingerprinte7d54aa2d9beaa4e
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in MarcoGorelli/auto-walrus