
Bug hunt
The Preview That Secretly Writes
The scariest bug a tool can have: a preview that isn't one. Pip ran
tidy("inbox") in preview mode to check the plan first. The files
moved anyway, and a new tidy folder appeared.
In a trustworthy preview, every change sits behind if apply:.
Changes include rename(), mkdir(), write_text(), unlink()
and open(..., "w"). Reading and printing are fine.
if apply:
target.parent.mkdir(exist_ok=True)
source.rename(target)
else:
print(f"would move {source.name}")
The bug
tidy(folder, apply=False) should move every file into a tidy
subfolder with a clean name, but only when apply is True. In
preview mode it should only print would move OLD -> NEW lines.
Right now the preview creates a folder and moves the files.
Assignment
Fix tidy so that:
- With
apply=False, it prints onewould move OLD -> NEWline per file and changes nothing on disk. - With
apply=True, it makes thetidyfolder, moves each file, and printsmoved OLD -> NEW. - It still returns the plan.
Fix tidy so that:
- With
apply=False, it prints onewould move OLD -> NEWline per file and changes nothing on disk. - With
apply=True, it makes thetidyfolder, moves each file, and printsmoved OLD -> NEW. - It still returns the plan.
main.py Python sleeping
Press Run to try your code, then Check to test it.