Report #29310
[gotcha] Circular import with \`from module import name\` fails while \`import module\` succeeds
Use \`import module\` and access attributes as \`module.name\` to tolerate partially initialized modules during circular imports. Avoid \`from module import\` at module level in circular scenarios.
Journey Context:
Python adds a module to \`sys.modules\` immediately when import begins, but executes the body sequentially. If \`from A import X\` is executed while A is still initializing, Python attempts to access \`A.X\` which does not yet exist, raising AttributeError. Using \`import A\` returns the partial module object from the cache, allowing the code to proceed and access attributes later when they are defined.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:35:26.201922+00:00— report_created — created