docs: fix conflicting lazy heavy import guidance in STYLEGUIDE.md (#759) - #920
docs: fix conflicting lazy heavy import guidance in STYLEGUIDE.md (#759)#920chethanuk wants to merge 2 commits into
Conversation
STYLEGUIDE.md recommended `from data_designer.lazy_heavy_imports import pd, np`, which is an attribute read against the PEP-562 facade and therefore imports pandas eagerly while the consuming module is still importing. Only `import data_designer.lazy_heavy_imports as lazy` + `lazy.pd` stays lazy, which is what lazy_heavy_imports.py's docstring already requires and what test_lazy_imports.py already asserts. Rewrites the four STYLEGUIDE.md blocks to the alias form, gives each snippet a call site so the TYPE_CHECKING imports are motivated, and adds `from __future__ import annotations` so the annotations resolve at def-time. Converts scripts/benchmarks/benchmark_engine_v2.py, the tree's only remaining user of the banned form. Also extends test_lazy_imports.py's guard to cover scripts/, since it previously only globbed packages/*/src and missed scripts/benchmarks/benchmark_engine_v2.py's banned from-import form. Signed-off-by: ChethanUK <chethanuk@outlook.com>
|
Thank you for your submission! We ask that you all sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text: I have read the DCO document and I hereby sign the DCO. 1 out of 2 committers have signed the DCO. |
|
|
Issue #759 received the |
|
Thanks for putting this together, @chethanuk! SummaryThis aligns Before merge, @chethanuk, please address the DCO Assistant request by following the bot's instructions to acknowledge the DCO, then comment FindingsNo findings. What Looks Good
VerdictShip it — the code changes are ready; merge remains pending the DCO acknowledgment requested above. This review was generated by an AI assistant. |
📋 Summary
STYLEGUIDE.mdandlazy_heavy_imports.pyrecommend opposite import forms for lazy-loadingheavy dependencies.
from data_designer.lazy_heavy_imports import pd, npis an attribute readagainst the module's PEP-562
__getattr__facade, so it fires while the consuming module isstill importing and pandas loads eagerly — the facade buys nothing. Only
import data_designer.lazy_heavy_imports as lazy+lazy.pdstays lazy, which is what themodule's own docstring already requires and what
test_lazy_imports.pyalready asserts. Thisaligns the guide to the form that actually works.
🔗 Related Issue
Fixes #759
🔄 Changes
STYLEGUIDE.md: rewrite the four blocks that taught thefrom ... import pd, npform to usethe
import ... as lazy/lazy.pdform instead. Each example gains a call site andfrom __future__ import annotationsso the snippets are runnable modules rather thanillustrations that raise
NameErrorif copy-pasted.scripts/benchmarks/benchmark_engine_v2.py: convert the tree's only remaining user of thebanned form to the alias pattern.
packages/data-designer/tests/test_lazy_imports.py: addtest_scripts_avoid_from_lazy_heavy_imports_pattern, extending the existingpackages/*/src/**guard toscripts/**— the gap that let the benchmark script drift.🧪 Testing
make test—test_lazy_imports.py: 1 failed, 4 passed before the fix (fails onbenchmark_engine_v2.py); 5 passed aftermake lint/make format-check— all checks passedmake test-interface— 1119 passed, 1 skipped, 1 pre-existing failure(
test_import_performance, an environmentalmake perf-importtimeout under machine load,reproduced identically on
mainwith none of this branch's changes applied)dataset_hash✅ Checklist
git commit -sNote: issue #759 does not currently carry the
triagedlabel; the upstreamlinked-issue workflow may gate on that independent of this PR.
Fixes #759