File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -181,18 +181,21 @@ def scan_subpackages(cls, package: str) -> Sequence[str]:
181181class DeferLoad :
182182 """Helper to defer loading of a class definition."""
183183
184+ _class_cache = {} # Shared cache for resolved classes
185+
184186 def __init__ (self , cls_path : str ):
185187 """Initialize the `DeferLoad` instance with a qualified class path."""
186188 self ._cls_path = cls_path
187- self ._inst = None
188189
189190 def __call__ (self , * args , ** kwargs ):
190191 """Magic method to call the `DeferLoad` as a function."""
191- return ( self .resolved ) (* args , ** kwargs )
192+ return self .resolved (* args , ** kwargs )
192193
193194 @property
194195 def resolved (self ):
195196 """Accessor for the resolved class instance."""
196- if not self ._inst :
197- self ._inst = ClassLoader .load_class (self ._cls_path )
198- return self ._inst
197+ if self ._cls_path not in DeferLoad ._class_cache :
198+ DeferLoad ._class_cache [self ._cls_path ] = ClassLoader .load_class (
199+ self ._cls_path
200+ )
201+ return DeferLoad ._class_cache [self ._cls_path ]
You can’t perform that action at this time.
0 commit comments