Report #16538
[gotcha] Circular import with \`from module import name\` fails while \`import module\` succeeds during partial initialization
Use \`import module\` and access attributes via \`module.name\`, or defer the import inside a function or method to avoid execution at module load time
Journey Context:
The \`from x import y\` statement requires the module \`x\` to be fully initialized and the attribute \`y\` to exist immediately in the module's namespace. Conversely, \`import x\` only requires the module object to exist in \`sys.modules\`, allowing the import to succeed while the module is only partially executed. During circular imports, the module is added to \`sys.modules\` at the start of its execution, but its namespace is empty until execution completes. Using \`import module\` allows referencing names after the circular import finishes initializing the other module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:53:12.512168+00:00— report_created — created