From: Christian Heller Date: Sat, 16 Mar 2024 23:44:33 +0000 (+0100) Subject: Add type hints. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/todos?a=commitdiff_plain;h=bf0868a41a86ea5952d5fc1a8fca6621e89ad42e;p=plomtask Add type hints. --- diff --git a/days.py b/days.py index 12328a6..42fc4c1 100644 --- a/days.py +++ b/days.py @@ -8,7 +8,7 @@ DATE_FORMAT = '%Y-%m-%d' class Day: """Individual days defined by their dates.""" - def __init__(self, date): + def __init__(self, date:str): self.date = date self.datetime = datetime.strptime(date, DATE_FORMAT) @@ -17,8 +17,8 @@ class Day: """Return what weekday matches self.date.""" return self.datetime.strftime('%A') - def __eq__(self, other): - return self.date == other.date + def __eq__(self, other:object): + return isinstance(other, self.__class__) and self.date == other.date - def __lt__(self, other): + def __lt__(self, other:Day): return self.date < other.date diff --git a/task.py b/task.py index 3af1cac..4774c8c 100755 --- a/task.py +++ b/task.py @@ -18,13 +18,13 @@ class HandledException(Exception): class TaskHandler(BaseHTTPRequestHandler): """Handles single HTTP request.""" - def send_html(self, html, code=200): + def send_html(self, html:str, code:int=200): """Send HTML as proper HTTP response.""" self.send_response(code) self.end_headers() self.wfile.write(bytes(html, 'utf-8')) - def send_msg(self, msg, code=400): + def send_msg(self, msg:str, code:int=400): """Send message in HTML formatting as HTTP response.""" html = self.server.jinja.get_template('msg.html').render(msg=msg) self.send_html(html, code)