From 0f4ef69602ff2dd279d642f4339573c9d40fcb16 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 3 Oct 2024 12:06:22 -0400 Subject: [PATCH] Defer import of Segmenter to speed up help message printing Still allows Segmenter to be imported by a user, but bypasses its heavy imports until called directly --- src/wing_segmenter/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wing_segmenter/__init__.py b/src/wing_segmenter/__init__.py index 703337b..fc472bb 100644 --- a/src/wing_segmenter/__init__.py +++ b/src/wing_segmenter/__init__.py @@ -1,3 +1,7 @@ __version__ = "0.1.0" -from wing_segmenter.segmenter import Segmenter +def __getattr__(name): + if name == 'Segmenter': + from wing_segmenter.segmenter import Segmenter + return Segmenter + raise AttributeError(f"module {__name__} has no attribute {name}")