diff options
Diffstat (limited to 'yt_dlp/compat/compat_utils.py')
-rw-r--r-- | yt_dlp/compat/compat_utils.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/yt_dlp/compat/compat_utils.py b/yt_dlp/compat/compat_utils.py index b1d58f5b9..8da4fcc0a 100644 --- a/yt_dlp/compat/compat_utils.py +++ b/yt_dlp/compat/compat_utils.py @@ -33,7 +33,7 @@ def _is_package(module): def passthrough_module(parent, child, *, callback=lambda _: None): parent_module = importlib.import_module(parent) - child_module = importlib.import_module(child, parent) + child_module = None # Import child module only as needed class PassthroughModule(types.ModuleType): def __getattr__(self, attr): @@ -41,6 +41,9 @@ def passthrough_module(parent, child, *, callback=lambda _: None): with contextlib.suppress(ImportError): return importlib.import_module(f'.{attr}', parent) + nonlocal child_module + child_module = child_module or importlib.import_module(child, parent) + ret = _NO_ATTRIBUTE with contextlib.suppress(AttributeError): ret = getattr(child_module, attr) |