fix(imports): lazy package exports — no import cycle, no Arelle or rdflib for callers that don't need them - #74
Merged
Conversation
`import xbrlkit.periods` as a first import failed in 0.18.1: periods imports xbrlkit.parse.ids, importing any parse submodule runs parse/__init__.py, and that eagerly imported arelle_load and to_model, which imports periods while it is half-loaded. parse/__init__.py now resolves its exports on first use (PEP 562), so the cycle is gone and a caller that only wants a period id no longer loads Arelle. tests/test_imports.py imports every public module in its own interpreter, so an order-dependent import fails CI instead of a user.
Member
Author
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 2m 41s —— View job Review: PR #74 — fix(parse): load the Arelle-backed exports lazily
SummaryConfirmed the root cause and the fix. The chain is real:
|
…I never pulls in rdflib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
import xbrlkit.periodsas a first import fails on 0.18.1 with a circular-importImportError.periodsimportsxbrlkit.parse.ids; importing anyparsesubmodule runsparse/__init__.py, which eagerly importedarelle_loadandto_model, andto_modelimportsperiodswhile it is still half-loaded. The usual entry points import in an order that hides it, butperiodsis a public module.Changes
xbrlkit/parse/__init__.py: the eight exports (load_model,to_xbrl_model,close, …) resolve on first use through a module__getattr__(PEP 562), with the imports kept underTYPE_CHECKINGfor type checkers.from xbrlkit.parse import to_xbrl_modelworks as before. The cycle is gone, and a caller that only wants a period id (xbrlkit.periods) no longer loads Arelle.xbrlkit/serialize/__init__.py,xbrlkit/deserialize/__init__.py: the same lazy pattern. Both packages imported every projection eagerly, so importingxbrlkit.serialize.taviorxbrlkit.deserialize.taviloaded rdflib through the holon and graph modules. TAVI is JSON; it now loads no RDF stack. Public names are unchanged.tests/test_imports.py: every public module imported in its own interpreter (48 modules), plus checks thatxbrlkit.periodsdoes not load Arelle and that the two TAVI modules do not load rdflib. Against 0.18.1, exactlyxbrlkit.periodsand the Arelle check fail.Output Impact
INTERNAL. No emitted file and no CLI command changes;
xbrlkit.parse's exports are the same names.Testing
just test-all: 603 passed, 2 skipped; ruff, format and basedpyright clean.uvx --from xbrlkit==0.18.1 python -c "import xbrlkit.periods"raises theImportError.🤖 Generated with Claude Code