Report #70386
[gotcha] AttributeError: partially initialized module 'X' has no attribute 'Y' \(most likely due to a circular import\)
Restructure to avoid circular imports \(extract shared code to a third module\) or use lazy imports \(import inside functions/methods\) to ensure modules are fully initialized before accessing their attributes.
Journey Context:
Python adds the module object to sys.modules at the very start of the import process. If module A imports B at top-level, and B tries to import A, A already exists in sys.modules but is empty \(partially initialized\). Accessing attributes defined later in A fails with AttributeError. Lazy imports \(moving the import statement inside a function or method\) delay the lookup until after all top-level code has run, breaking the cycle by ensuring full initialization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:43:15.403549+00:00— report_created — created