@@ -41,6 +41,17 @@ def __init__(
4141 version: DD version string, e.g. "3.38.1".
4242 xml_path: XML file containing data dictionary definition.
4343 """
44+ if version is None and xml_path is None :
45+ # Defer loading the DD definitions until we really need them
46+ self .__deferred_init = True
47+ else :
48+ # If a specific version or xml_path is requested, we still load immediately
49+ # so any exceptions are raise when creating the IDSfactory
50+ self .__do_init (version , xml_path )
51+ self .__deferred_init = False
52+
53+ def __do_init (self , version : str | None , xml_path : str | pathlib .Path | None ):
54+ """Actual initialization logic"""
4455 self ._xml_path = xml_path
4556 self ._etree = dd_zip .dd_etree (version , xml_path )
4657 self ._ids_elements = {
@@ -71,10 +82,16 @@ def __dir__(self) -> Iterable[str]:
7182 return sorted (set (object .__dir__ (self )).union (self ._ids_elements ))
7283
7384 def __getattr__ (self , name : str ) -> Any :
85+ # Actually initialize when we deferred it before
86+ if self .__deferred_init :
87+ self .__do_init (None , None )
88+ self .__deferred_init = False
89+ return getattr (self , name )
90+ # Check if the name matches any IDS and return a 'constructor' for it
7491 if name in self ._ids_elements :
7592 # Note: returning a partial to mimic AL HLI, e.g. factory.core_profiles()
7693 return partial (IDSToplevel , self , self ._ids_elements [name ])
77- raise AttributeError (f"{ type ( self )!r } object has no attribute { name !r} " )
94+ raise AttributeError (f"'IDSFactory' has no attribute { name !r} " )
7895
7996 def __iter__ (self ) -> Iterator [str ]:
8097 """Iterate over the IDS names defined by the loaded Data Dictionary"""
0 commit comments