From: Ralf Jung Date: Sat, 8 Nov 2014 22:20:34 +0000 (+0100) Subject: experiment with mypy type annotations X-Git-Url: https://git.ralfj.de/zonemaker.git/commitdiff_plain/fe551749af05a1ac3cb09a4640aa6c9cc8556212?ds=sidebyside experiment with mypy type annotations --- diff --git a/zonemaker/zone.py b/zonemaker/zone.py index 435b039..f5db2a8 100644 --- a/zonemaker/zone.py +++ b/zonemaker/zone.py @@ -1,3 +1,4 @@ +from typing import List, Dict, Any import ipaddress, re second = 1 @@ -5,7 +6,7 @@ minute = 60*second hour = 60*minute day = 24*hour -def hostname(name): +def hostname(name: str) -> str: # check hostname for validity label = r'[a-zA-Z90-9]([a-zA-Z90-9-]{0,61}[a-zA-Z90-9])?' # must not start or end with hyphen pattern = r'^{0}(\.{0})*\.?'.format(label) @@ -43,10 +44,10 @@ class Delegation(): pass class Zone: - def __init__(self, name, mail, NS, - secondary_refresh, secondary_retry, secondary_discard, - NX_TTL = None, A_TTL = None, other_TTL = None, - domains = []): + def __init__(self, name: str, mail: str, NS: List[str], + secondary_refresh: int, secondary_retry: int, secondary_discard: int, + NX_TTL: int = None, A_TTL: int = None, other_TTL: int = None, + domains: Dict[str, Any] = {}) -> None: self._name = hostname(name) if not mail.endswith('.'): raise Exception("Mail must be absolute, end with a dot") atpos = mail.find('@')