Add type hints

This commit is contained in:
Changhua
2022-10-23 00:02:33 +08:00
parent d526d15ea3
commit cd11aa7ed0
4 changed files with 12 additions and 11 deletions

View File

@@ -23,7 +23,7 @@ class Config(object):
return yconfig
def reload(self):
def reload(self) -> None:
yconfig = self._load_config()
logging.config.dictConfig(yconfig["logging"])
self.GROUPS = yconfig["groups"]["enable"]

View File

@@ -23,10 +23,10 @@ class Chengyu(object):
return cys, zis, yins
def isChengyu(self, cy):
def isChengyu(self, cy: str) -> bool:
return self.cys.get(cy, None) is not None
def getNext(self, cy, tongyin=True) -> str:
def getNext(self, cy: str, tongyin: bool = True) -> str:
"""获取下一个成语
cy: 当前成语
tongyin: 是否允许同音字
@@ -56,7 +56,7 @@ class Chengyu(object):
return None
def getMeaning(self, cy):
def getMeaning(self, cy: str) -> str:
ress = self.df[self.df["chengyu"] == cy].to_dict(orient="records")
if ress:
res = ress[0]

View File

@@ -2,13 +2,14 @@
import time
import schedule
from typing import Any, Callable
class Job(object):
def __init__(self) -> None:
pass
def onEverySeconds(self, seconds, task, *args, **kwargs):
def onEverySeconds(self, seconds: int, task: Callable[..., Any], *args, **kwargs) -> None:
"""
每 seconds 秒执行
:param seconds: 间隔,秒
@@ -17,7 +18,7 @@ class Job(object):
"""
schedule.every(seconds).seconds.do(task, *args, **kwargs)
def onEveryMinutes(self, minutes, task, *args, **kwargs):
def onEveryMinutes(self, minutes: int, task: Callable[..., Any], *args, **kwargs) -> None:
"""
每 minutes 分钟执行
:param minutes: 间隔,分钟
@@ -26,7 +27,7 @@ class Job(object):
"""
schedule.every(minutes).minutes.do(task, *args, **kwargs)
def onEveryHours(self, hours, task, *args, **kwargs):
def onEveryHours(self, hours: int, task: Callable[..., Any], *args, **kwargs) -> None:
"""
每 hours 小时执行
:param hours: 间隔,小时
@@ -35,7 +36,7 @@ class Job(object):
"""
schedule.every(hours).hours.do(task, *args, **kwargs)
def onEveryDays(self, days, task, *args, **kwargs):
def onEveryDays(self, days: int, task: Callable[..., Any], *args, **kwargs) -> None:
"""
每 days 天执行
:param days: 间隔,天
@@ -44,7 +45,7 @@ class Job(object):
"""
schedule.every(days).days.do(task, *args, **kwargs)
def onEveryTime(self, times, task, *args, **kwargs):
def onEveryTime(self, times: int, task: Callable[..., Any], *args, **kwargs) -> None:
"""
每天定时执行
:param times: 时间字符串列表,格式:
@@ -62,7 +63,7 @@ class Job(object):
for t in times:
schedule.every(1).days.at(t).do(task, *args, **kwargs)
def runPendingJobs(self):
def runPendingJobs(self) -> None:
schedule.run_pending()

View File

@@ -7,7 +7,7 @@ from wcferry import Wcf
from robot import Robot
def weather_report(robot: Robot):
def weather_report(robot: Robot) -> None:
"""模拟发送天气预报
"""
# 获取接收人