Report #6939
[gotcha] Circular import with \`from module import name\` causes AttributeError on partially initialized module
Use \`import module\` and access attributes as \`module.name\`, or move the import inside the function/method where it is used. Avoid \`from X import Y\` at module level in circular dependency chains.
Journey Context:
When Python encounters \`from X import Y\` during a circular import, it returns the partially initialized module object from sys.modules. If \`Y\` is defined later in the module's execution, accessing it raises AttributeError because the module dict is still incomplete. Using \`import X\` delays attribute resolution until after the module finishes loading, bypassing the partial initialization window. This is a fundamental limitation of Python's import system: the module cache is populated at the start of loading, so circular imports always see intermediate states.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:22:08.260846+00:00— report_created — created