perf(import): stop loading hwpx.hwp5 and hwpx.tools on import hwpx - #388
Merged
Merged
Conversation
import hwpx loaded hwpx.hwp5 and hwpx.hwp5.errors only to export Hwp5Error and Hwp5ConversionWarning. Both now live in hwpx.errors, and hwpx.hwp5.errors re-exports the same classes, so identity and except hwpx.Hwp5Error are unchanged. HwpxDocument imports Hwp5ConversionReport for type checking only; the converter already loaded on first .hwp read or write. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
import hwpx imported all twelve hwpx.tools modules (exporter, viewers, diff, mail merge, validators) to bind 19 stable names. Those names now resolve through the module __getattr__ on first access, with no warning, as the same objects, and are cached in the module globals; dir(hwpx), from hwpx import * and hwpx.tools keep working. A TYPE_CHECKING import keeps their static types. The lookup uses a static import, so the pinned importlib call sites and export maps are unchanged; only the __getattr__ fingerprint is re-pinned in scripts/check_product_boundary.py. import hwpx: 115 -> 97 hwpx modules. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
import hwpx no longer loads hwpx.hwp5 or hwpx.tools, so it loads 97 hwpx modules instead of 117 (scripts/size_ratchet.py --lower-bound). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #387.
What
Hwp5Error/Hwp5ConversionWarningare now defined inhwpx.errors(which already registers thehwp5-*codes);hwpx.hwp5.errorsre-exports the same classes.import hwpxno longer loads anyhwpx.hwp5module.hwpx.tools(TextExtractor,doc_diff,validate_package, ...) resolve on first access throughhwpx.__getattr__: same objects, no warning, cached after first lookup.hwpx.toolsstays reachable after a plainimport hwpx,dir()/from hwpx import *still cover__all__, and aTYPE_CHECKINGblock keeps their static types.tests/data/import_breadth.jsonbound lowered 117 → 97.The product-boundary check pins
hwpx.__getattr__by fingerprint; that pin is updated here. The new branch imports one fixed module statically (import hwpx.tools as tools); noimportlib.import_modulecall site or export map changed.Measured (best of 5, same machine)
import hwpximport hwpximport timeHwpxDocument.new()The first save still loads all tool modules through
hwpx/tools/__init__.py(~9 ms); that andimportlib.metadatain ingest are #386.hwpx.oxml(~half of what remains) is required byHwpxDocument.Tests
tests/test_lazy_hwp5_import.py(6) andtests/test_lazy_tools_import.py(5), subprocess-based with-W error. The "no hwpx.hwp5 / no hwpx.tools in sys.modules" tests failed before the change. The identity,.hwpsave/reopen, damaged-OLE2 error,__all__/dir()and attribute-access guards pass before and after.capabilities --verify, contract docs, size ratchet (97/97), layer-leak guard pass.🤖 Generated with Claude Code