修复一些PyCharm警告

This commit is contained in:
John Smith 2021-07-17 13:03:45 +08:00
parent 335248c076
commit 6a4faa83a4
6 changed files with 16 additions and 12 deletions

View File

@ -7,6 +7,10 @@ import tornado.web
# noinspection PyAbstractClass
class ApiHandler(tornado.web.RequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.json_args = None
def set_default_headers(self):
# 跨域测试用
if not self.application.settings['debug']:
@ -18,13 +22,12 @@ class ApiHandler(tornado.web.RequestHandler):
self.request.headers['Access-Control-Request-Headers'])
def prepare(self):
if self.request.headers.get('Content-Type', '').startswith('application/json'):
try:
self.json_args = json.loads(self.request.body)
except json.JSONDecodeError:
self.json_args = None
else:
self.json_args = None
if not self.request.headers.get('Content-Type', '').startswith('application/json'):
return
try:
self.json_args = json.loads(self.request.body)
except json.JSONDecodeError:
pass
async def options(self, *_args, **_kwargs):
# 跨域测试用

View File

@ -121,7 +121,7 @@ class AppConfig:
self.translator_configs = translator_configs
def _str_to_list(value, item_type: Type=str, container_type: Type=list):
def _str_to_list(value, item_type: Type = str, container_type: Type = list):
value = value.strip()
if value == '':
return container_type()

View File

@ -60,6 +60,7 @@ def init_logging(debug):
file_handler = logging.handlers.TimedRotatingFileHandler(
LOG_FILE_NAME, encoding='utf-8', when='midnight', backupCount=7, delay=True
)
# noinspection PyArgumentList
logging.basicConfig(
format='{asctime} {levelname} [{name}]: {message}',
datefmt='%Y-%m-%d %H:%M:%S',

View File

@ -25,7 +25,7 @@ _avatar_url_cache: Dict[int, str] = {}
# 正在获取头像的Futureuser_id -> Future
_uid_fetch_future_map: Dict[int, asyncio.Future] = {}
# 正在获取头像的user_id队列
_uid_queue_to_fetch = None
_uid_queue_to_fetch: Optional[asyncio.Queue] = None
# 上次被B站ban时间
_last_fetch_banned_time: Optional[datetime.datetime] = None

View File

@ -13,7 +13,7 @@ engine = None
DbSession: Optional[Type[sqlalchemy.orm.Session]] = None
def init(debug):
def init(_debug):
cfg = config.get_config()
global engine, DbSession
# engine = sqlalchemy.create_engine(cfg.database_url, echo=debug)
@ -28,7 +28,7 @@ def get_session():
session = DbSession()
try:
yield session
except:
except BaseException:
session.rollback()
raise
finally:

View File

@ -23,7 +23,7 @@ NO_TRANSLATE_TEXTS = {
}
_main_event_loop = asyncio.get_event_loop()
_http_session = None
_http_session: Optional[aiohttp.ClientSession] = None
_translate_providers: List['TranslateProvider'] = []
# text -> res
_translate_cache: Dict[str, str] = {}