aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/compat/compat_utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-06-15 18:00:34 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-06-16 06:23:50 +0530
commit560738f34de4df6eaf82290fd503def3f366f878 (patch)
treeabaf12930736e70b39a3a1b45500408ca020cf2c /yt_dlp/compat/compat_utils.py
parent99d10bf60796a90d2ca421ec63f1208b15ae5f48 (diff)
downloadhypervideo-pre-560738f34de4df6eaf82290fd503def3f366f878.tar.lz
hypervideo-pre-560738f34de4df6eaf82290fd503def3f366f878.tar.xz
hypervideo-pre-560738f34de4df6eaf82290fd503def3f366f878.zip
[extractor] Import `_ALL_CLASSES` lazily
This significantly speeds up `import yt_dlp` in the absence of `lazy_extractors`
Diffstat (limited to 'yt_dlp/compat/compat_utils.py')
-rw-r--r--yt_dlp/compat/compat_utils.py5
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)