Summary
STYLEGUIDE.md and lazy_heavy_imports.py give conflicting guidance on importing heavy third-party libraries. The two sources should be aligned to clarify the expected pattern to use when writing new code.
The style guide
STYLEGUIDE.md notes that large dependencies should be lazy-loaded by importing the library alias from the data_designer.lazy_heavy_imports module:
|
# Use lazy loading with IDE support |
|
from typing import TYPE_CHECKING |
|
from data_designer.lazy_heavy_imports import pd, np |
STYLEGUIDE.md also explains that any newly added heavy dependencies (e.g., your_lib) should use that same pattern:
|
from data_designer.lazy_heavy_imports import your_lib |
The module docstring
In lazy_heavy_imports.py, the docstring warns against the exact pattern that STYLEGUIDE.md recommended:
|
Important: |
|
Avoid `from data_designer.lazy_heavy_imports import pd`. |
|
That import style resolves the attribute immediately and eagerly imports the heavy dependency. |
Proposed resolution
Align both documentation sources to the same pattern to avoid confusion about which method is preferable, i.e., either importing the library alias from lazy_heavy_imports:
from data_designer.lazy_heavy_imports import pd, np
or importing the lazy_heavy_imports module and accessing its attributes at runtime:
import data_designer.lazy_heavy_imports as lazy
# ...when needed in the code:
df = lazy.pd.DataFrame(...)
Summary
STYLEGUIDE.mdandlazy_heavy_imports.pygive conflicting guidance on importing heavy third-party libraries. The two sources should be aligned to clarify the expected pattern to use when writing new code.The style guide
STYLEGUIDE.mdnotes that large dependencies should be lazy-loaded by importing the library alias from thedata_designer.lazy_heavy_importsmodule:DataDesigner/STYLEGUIDE.md
Lines 145 to 147 in 7c2c15e
STYLEGUIDE.mdalso explains that any newly added heavy dependencies (e.g.,your_lib) should use that same pattern:DataDesigner/STYLEGUIDE.md
Line 176 in 7c2c15e
The module docstring
In
lazy_heavy_imports.py, the docstring warns against the exact pattern thatSTYLEGUIDE.mdrecommended:DataDesigner/packages/data-designer-config/src/data_designer/lazy_heavy_imports.py
Lines 19 to 21 in 7c2c15e
Proposed resolution
Align both documentation sources to the same pattern to avoid confusion about which method is preferable, i.e., either importing the library alias from
lazy_heavy_imports:or importing the
lazy_heavy_importsmodule and accessing its attributes at runtime: