Report #78618
[gotcha] AttributeError or 'partially initialized module' errors when importing between submodules in a package
Use absolute \`import submodule\` \(binding the module object\) instead of \`from .submodule import name\` \(attribute access\) when dealing with circular imports, OR move shared code to a third separate module, OR use \`if TYPE\_CHECKING\` to import only for type hints
Journey Context:
Python's import system first creates a module object and puts it in \`sys.modules\`, then executes the module code. If during execution it encounters \`from . import foo\`, it attempts to get attribute \`foo\` from the partially initialized parent package. If \`foo\` hasn't finished importing yet \(circular\), you get 'partially initialized module 'foo' has no attribute 'bar'' or ImportError. Using \`import foo\` binds the module object itself, which exists in \`sys.modules\` even if not fully executed, avoiding the attribute access until later. This is the only way to handle cycles without restructuring, but it requires accessing attributes as \`foo.bar\` after import completes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:33:08.429650+00:00— report_created — created