Skip to content

Commit cbfa652

Browse files
timsaucerclaude
andcommitted
docs(ipc): explain why _resolve_ctx imports SessionContext lazily
The `# noqa: PLC0415` flag silenced ruff's "import outside top-level" lint but didn't say why the import was placed there in the first place. Add a comment naming the actual reason: `datafusion/__init__.py` imports `datafusion.ipc` before `datafusion.context`, so a module-top import would force `datafusion.context` to load mid-init of `datafusion.ipc`. The cycle is benign today (`context.py` only pulls `expr.py` at module scope, and neither pulls `ipc.py` back), but a single new import added to `context.py`'s transitive dependency tree could turn this into a real circular import. Deferring keeps `datafusion.ipc` import-order-independent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 865d9df commit cbfa652

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

python/datafusion/ipc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def _resolve_ctx(
159159
worker = get_worker_ctx()
160160
if worker is not None:
161161
return worker
162+
# Lazy import: `datafusion/__init__.py` imports `datafusion.ipc`
163+
# before `datafusion.context`, so a module-top import would force
164+
# `datafusion.context` to load mid-init of `datafusion.ipc`. The
165+
# cycle is benign today (context.py only pulls expr.py at module
166+
# scope, neither pulls ipc.py back), but a single new import in
167+
# context.py's transitive deps could turn it into a real cycle.
168+
# Deferring keeps `datafusion.ipc` import-order-independent.
162169
from datafusion.context import SessionContext # noqa: PLC0415
163170

164171
return SessionContext.global_ctx()

0 commit comments

Comments
 (0)