added type hints for function parameters and return values

Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
klux2 2019-05-12 15:21:26 +02:00
parent d2989e4857
commit 53c742035b

View file

@ -47,7 +47,7 @@ datum = None
class HSMensaW(telepot.aio.helper.ChatHandler):
@staticmethod
async def on_chat_message(msg):
async def on_chat_message(msg: dict) -> None:
global config, essen, status, var
content_type, chat_type, chat_id = telepot.glance(msg)
@ -114,7 +114,7 @@ class HSMensaW(telepot.aio.helper.ChatHandler):
write_config()
async def send_essen(chat_id):
async def send_essen(chat_id: int) -> None:
global datum, essen
nachricht = "Speiseplan am %s, den %s:\n" % (wochentage[datum.weekday()], datum.strftime("%d. MONAT %Y"))
nachricht = nachricht.replace("MONAT", monate[(datum.month - 1) % 12])
@ -123,7 +123,7 @@ async def send_essen(chat_id):
send_message(bot_obj=bot, chat_id=chat_id, msg=nachricht, parse_mode="markdown")
async def send_status(text):
async def send_status(text: str) -> None:
global config_ids
for chat_id in config_ids:
send_message(bot_obj=bot, chat_id=chat_id, msg=text)
@ -143,8 +143,7 @@ def send_message(bot_obj: DelegatorBot, chat_id: int, msg: str, parse_mode: Any
ids.remove(chat_id)
config['ids'] = ids
chat = get_chat_name(msg=msg)
await send_status("Bot wurde blockiert für Chat %s (ID: %i)" % (chat, chat_id))
await send_status("Bot wurde blockiert für Chat ID %i)" % chat_id)
write_config()
@ -154,7 +153,7 @@ def write_config() -> None:
json.dump(config, outfile)
async def get_essen(only_today):
async def get_essen(only_today: bool) -> None:
global datum, essen, var # , ctx
essen = []
try:
@ -202,7 +201,7 @@ async def get_essen(only_today):
essen.append(Essen(name, preis, kategorie))
def get_bot_id():
def get_bot_id() -> int:
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
with urllib.request.urlopen(api_url) as response:
data = json.load(response)
@ -210,7 +209,7 @@ def get_bot_id():
return bot_id
def get_chat_name(msg):
def get_chat_name(msg: dict) -> str:
if msg["chat"]["type"] == "group":
chat = msg["chat"]["title"] + " (g)"
elif msg["chat"]["type"] == "private":
@ -230,7 +229,7 @@ def shutdown(signum, frame):
sys.exit(-1)
async def essen_loop():
async def essen_loop() -> None:
global status, essen, ids
while True:
now = datetime.datetime.today()