Report #41175
[gotcha] isinstance checks fail after importlib.reload due to class identity change
Avoid reload\(\) in production; in interactive/Jupyter environments, re-instantiate objects after reload; use type name string comparison or duck typing instead of isinstance when hot-reloading
Journey Context:
importlib.reload\(\) re-executes the module code, creating new class objects with distinct identities in memory. Existing instances remain instances of the old class \(old identity\), so isinstance\(obj, NewClass\) returns False even though the source code is identical. This breaks debugging workflows, Jupyter notebook development, and hot-reloading plugin architectures. The only robust solutions are to recreate instances after reload, or avoid isinstance checks in favor of duck typing or string-based type name checks when dynamic reloading is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:35:09.084817+00:00— report_created — created