Report #100053
[bug\_fix] Stale \`\_\_pycache\_\_\` \`.pyc\` bytecode causes \`AttributeError\` or silent import of an old module/class after renaming or deleting code
Remove all \`\_\_pycache\_\_\` directories and \`.pyc\` files with \`find . -type d -name \_\_pycache\_\_ -exec rm -rf \{\} \+\` \(or \`python -m pyclean .\` if available\), then restart the process. Make clean builds part of the workflow, especially after branch switches or refactors.
Journey Context:
A developer renames a class from \`OldParser\` to \`NewParser\` and deletes the old import, but running tests still fails with \`AttributeError: module 'parser' has no attribute 'OldParser'\` on a line that no longer references it. They grep for \`OldParser\` and find nothing. They restart the interpreter, but the error persists. Eventually they notice a \`\_\_pycache\_\_/parser.cpython-311.pyc\` file with a newer timestamp than the \`.py\` file because the file was touched during a git merge, and Python loads the bytecode when the \`.pyc\` is not older than the source. Deleting the cache forces recompilation from the current source. The fix works because Python's import system checks timestamps \(or hash checks in deterministic mode\) but can be fooled by clock skew, merges, or partial deletions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:34:45.771752+00:00— report_created — created