mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-06-11 20:08:29 +03:00
Refactor module-level deprecation code
This commit is contained in:
@@ -14,8 +14,18 @@ import warnings
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def _module_deprecation_helper(all, **names):
|
||||||
|
def __getattr__(name):
|
||||||
|
if name in names:
|
||||||
|
warnings.warn(f'{name} is deprecated, use {names[name].__name__} instead', DeprecatedFeatureWarning, stacklevel = 2)
|
||||||
|
return names[name]
|
||||||
|
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
|
||||||
|
def __dir__():
|
||||||
|
return sorted(all + list(names.keys()))
|
||||||
|
return __getattr__, __dir__
|
||||||
|
|
||||||
class DeprecatedPropertyAccessWarning(FutureWarning):
|
|
||||||
|
class DeprecatedFeatureWarning(FutureWarning):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +38,7 @@ class _DeprecatedProperty:
|
|||||||
def __get__(self, obj, objType):
|
def __get__(self, obj, objType):
|
||||||
if obj is None: # if the access is through the class using _DeprecatedProperty rather than an instance of the class:
|
if obj is None: # if the access is through the class using _DeprecatedProperty rather than an instance of the class:
|
||||||
return self
|
return self
|
||||||
warnings.warn(f'{self.name} is deprecated, use {self.replStr} instead', DeprecatedPropertyAccessWarning, stacklevel = 2)
|
warnings.warn(f'{self.name} is deprecated, use {self.replStr} instead', DeprecatedFeatureWarning, stacklevel = 2)
|
||||||
return self.repl(obj)
|
return self.repl(obj)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,17 +38,6 @@ import urllib3.util.ssl_
|
|||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
# DescriptionURL deprecation
|
|
||||||
_DEPRECATED_NAMES = {'DescriptionURL': 'TextLink'}
|
|
||||||
def __getattr__(name):
|
|
||||||
if name in _DEPRECATED_NAMES:
|
|
||||||
warnings.warn(f'{name} is deprecated, use {_DEPRECATED_NAMES[name]} instead', FutureWarning, stacklevel = 2)
|
|
||||||
return globals()[_DEPRECATED_NAMES[name]]
|
|
||||||
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
|
|
||||||
def __dir__():
|
|
||||||
return sorted(__all__ + list(_DEPRECATED_NAMES.keys()))
|
|
||||||
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
_API_AUTHORIZATION_HEADER = 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs=1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'
|
_API_AUTHORIZATION_HEADER = 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs=1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'
|
||||||
_globalGuestTokenManager = None
|
_globalGuestTokenManager = None
|
||||||
@@ -2082,3 +2071,6 @@ class TwitterTrendsScraper(_TwitterAPIScraper):
|
|||||||
for item in entry['content']['timelineModule']['items']:
|
for item in entry['content']['timelineModule']['items']:
|
||||||
trend = item['item']['content']['trend']
|
trend = item['item']['content']['trend']
|
||||||
yield Trend(name = trend['name'], metaDescription = trend['trendMetadata'].get('metaDescription'), domainContext = trend['trendMetadata']['domainContext'])
|
yield Trend(name = trend['name'], metaDescription = trend['trendMetadata'].get('metaDescription'), domainContext = trend['trendMetadata']['domainContext'])
|
||||||
|
|
||||||
|
|
||||||
|
__getattr__, __dir__ = snscrape.base._module_deprecation_helper(__all__, DescriptionURL = TextLink)
|
||||||
|
|||||||
Reference in New Issue
Block a user