Report #16716
[gotcha] isinstance checks fail after importlib.reload even for same-named classes
Avoid using importlib.reload in production. If hot-reloading is necessary, you must re-instantiate all objects of reloaded classes, or use a proxy/registration pattern that looks up class identity by name \(qualname \+ module\) rather than object identity. Never rely on isinstance checks across reload boundaries.
Journey Context:
Python's object model identifies classes by their memory address \(object identity\), not by name. When importlib.reload executes, it creates a \*new\* module object with new class objects. Existing instances retain references to the \*old\* class objects. Consequently, \`isinstance\(old\_instance, NewClass\)\` returns False because \`OldClass is not NewClass\`, even though both have the same \_\_name\_\_ and \_\_qualname\_\_. This breaks dispatch logic, serialization frameworks, and type checking. The fix recognizes that reload creates a schism between old and new types; you cannot bridge this with standard identity checks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:21:55.681529+00:00— report_created — created