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