Report #11428
[gotcha] importlib.reload breaking isinstance checks and object identity
After reload\(\), recreate all instances of classes from that module to ensure they reference the new class objects, or architect the code to avoid holding long-lived references to classes/functions from modules subject to reloading \(e.g., use factory patterns with re-import\).
Journey Context:
reload\(\) re-executes module code in the existing module dict, replacing class and function objects. Existing instances in memory retain references to old class objects. Code importing the class after reload gets the new class. Thus \`isinstance\(obj, NewClass\)\` returns False for pre-reload instances, and \`type\(obj\) is NewClass\` also fails. Pickle and inspect checks fail similarly. Common mistake: hot-reloading in a REPL or server and expecting existing objects to migrate to new classes. The fix acknowledges that reload creates new identities; state must be reconstructed or boundaries isolated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:18:23.623252+00:00— report_created — created