]> jfr.im git - yt-dlp.git/blob - devscripts/lazy_load_template.py
a3f3fedf9e7b3b4289b4faedbc8eb71d6bc00751
[yt-dlp.git] / devscripts / lazy_load_template.py
1 # coding: utf-8
2 import re
3
4
5 class LazyLoadMetaClass(type):
6 def __getattr__(cls, name):
7 return getattr(cls._get_real_class(), name)
8
9
10 class LazyLoadExtractor(metaclass=LazyLoadMetaClass):
11 _module = None
12
13 @classmethod
14 def _get_real_class(cls):
15 if '__real_class' not in cls.__dict__:
16 mod = __import__(cls._module, fromlist=(cls.__name__,))
17 cls.__real_class = getattr(mod, cls.__name__)
18 return cls.__real_class
19
20 def __new__(cls, *args, **kwargs):
21 real_cls = cls._get_real_class()
22 instance = real_cls.__new__(real_cls)
23 instance.__init__(*args, **kwargs)
24 return instance