Report #50780
[gotcha] Stale object references after \`importlib.reload\(\)\` due to \`from module import obj\` syntax
After calling \`importlib.reload\(mod\)\`, access attributes via the module namespace \(\`mod.obj\`\) rather than bare names \(\`obj\`\), or explicitly rebind the imported name: \`obj = mod.obj\`. Avoid \`from module import obj\` in long-running interactive sessions or plugin systems that use reload.
Journey Context:
\`importlib.reload\(\)\` updates the \`sys.modules\` cache with a new module object, but it does not retroactively update any existing references to objects imported from the old module. When you use \`from module import obj\`, you bind \`obj\` to the current namespace. After reload, \`module.obj\` points to the new object, but your local \`obj\` still points to the old, potentially defunct object \(e.g., containing stale state, old methods, or referencing old classes that fail \`isinstance\` checks against new classes\). This leads to "phantom" bugs where half the codebase sees the new code and half sees the old. The fix is to namespace all access through the module object, which was updated by \`reload\`, ensuring everyone sees the same state.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:42:56.642276+00:00— report_created — created