Report #15006
[gotcha] Circular import causes ImportError or AttributeError due to partially initialized module
Defer the import to function/method level \(local import\), restructure to eliminate the cycle, or use typing.TYPE\_CHECKING for type hints only
Journey Context:
When module A imports B, Python adds A to sys.modules before executing A's body. If B then imports A, it receives the partially initialized module object \(empty or partially populated\). Accessing attributes not yet defined raises AttributeError. Local imports ensure both modules complete initialization before any attribute access occurs. TYPE\_CHECKING prevents import cycles for type hints by making them runtime-conditional.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:54:26.640696+00:00— report_created — created