Report #6303
[gotcha] isinstance checks fail or methods not found after importlib.reload on a module containing classes
Avoid reload in production. If used for debugging, recreate all instances of reloaded classes after the reload; old instances reference the old class definition which is distinct from the new one. Use \`types.new\_class\` or manual migration if state must persist.
Journey Context:
Reload re-executes the module code in the existing module dict, but creates new class objects. Old instances retain a reference to the original class object \(the type\). \`isinstance\` checks the identity of the type, so old instances fail checks against the new class. Method resolution on old instances still uses the old class's method table. This is a fundamental constraint of the object model: types are first-class objects, and reload doesn't update existing references to them. The alternative \(magically updating all instances\) would require a global registry or weakrefs with high performance cost.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:44:36.144425+00:00— report_created — created