]>
jfr.im git - yt-dlp.git/blob - devscripts/lazy_load_template.py
4 from ..utils
import bug_reports_message
, write_string
7 class LazyLoadMetaClass(type):
8 def __getattr__(cls
, name
):
9 if '_real_class' not in cls
.__dict
__:
11 f
'WARNING: Falling back to normal extractor since lazy extractor '
12 f
'{cls.__name__} does not have attribute {name}{bug_reports_message()}')
13 return getattr(cls
._get
_real
_class
(), name
)
16 class LazyLoadExtractor(metaclass
=LazyLoadMetaClass
):
21 def _get_real_class(cls
):
22 if '_real_class' not in cls
.__dict
__:
23 mod
= __import__(cls
._module
, fromlist
=(cls
.__name
__,))
24 cls
._real
_class
= getattr(mod
, cls
.__name
__)
25 return cls
._real
_class
27 def __new__(cls
, *args
, **kwargs
):
28 real_cls
= cls
._get
_real
_class
()
29 instance
= real_cls
.__new
__(real_cls
)
30 instance
.__init
__(*args
, **kwargs
)