Refactor deprecated properties

This commit is contained in:
JustAnotherArchivist
2020-10-16 18:11:52 +00:00
parent e22b461563
commit 1bbe25647a
4 changed files with 17 additions and 25 deletions

View File

@@ -6,11 +6,23 @@ import json
import logging
import requests
import time
import warnings
logger = logging.getLogger(__name__)
class _DeprecatedProperty:
def __init__(self, name, repl, replStr):
self.name = name
self.repl = repl
self.replStr = replStr
def __get__(self, obj, objType):
warnings.warn(f'{self.name} is deprecated, use {self.replStr} instead', FutureWarning, stacklevel = 2)
return self.repl(obj)
def _json_serialise_datetime(obj):
'''A JSON serialiser that converts datetime.datetime and datetime.date objects to ISO-8601 strings.'''
if isinstance(obj, (datetime.datetime, datetime.date)):

View File

@@ -7,7 +7,6 @@ import re
import snscrape.base
import typing
import urllib.parse
import warnings
logger = logging.getLogger(__name__)
@@ -21,10 +20,7 @@ class FacebookPost(snscrape.base.Item):
content: typing.Optional[str]
outlinks: list
@property
def outlinksss(self):
warnings.warn('outlinksss is deprecated, use outlinks instead', FutureWarning)
return ' '.join(self.outlinks)
outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks')
def __str__(self):
return self.cleanUrl

View File

@@ -6,7 +6,6 @@ import re
import snscrape.base
import typing
import urllib.parse
import warnings
logger = logging.getLogger(__name__)
@@ -30,10 +29,7 @@ class TelegramPost(snscrape.base.Item):
outlinks: list
linkPreview: typing.Optional[LinkPreview] = None
@property
def outlinksss(self):
warnings.warn('outlinksss is deprecated, use outlinks instead', FutureWarning)
return ' '.join(self.outlinks)
outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks')
def __str__(self):
return self.url

View File

@@ -12,7 +12,6 @@ import string
import time
import typing
import urllib.parse
import warnings
logger = logging.getLogger(__name__)
@@ -41,20 +40,9 @@ class Tweet(snscrape.base.Item):
quotedTweet: typing.Optional['Tweet'] = None
mentionedUsers: typing.Optional[typing.List['User']] = None
@property
def username(self):
warnings.warn('username is deprecated, use user.username instead', FutureWarning)
return self.user.username
@property
def outlinksss(self):
warnings.warn('outlinksss is deprecated, use outlinks instead', FutureWarning)
return ' '.join(self.outlinks)
@property
def tcooutlinksss(self):
warnings.warn('tcooutlinksss is deprecated, use tcooutlinks instead', FutureWarning)
return ' '.join(self.tcooutlinks)
username = snscrape.base._DeprecatedProperty('username', lambda self: self.user.username, 'user.username')
outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks')
tcooutlinksss = snscrape.base._DeprecatedProperty('tcooutlinksss', lambda self: ' '.join(self.tcooutlinks), 'tcooutlinks')
def __str__(self):
return self.url