commit 8aa144c57c7a6825f45f2531bccf60bfa7cbec4c Author: vaydheesh Date: Wed Jun 12 20:08:48 2019 +0000 Modified: TypeAnnotation diff --git a/apertium/__init__.py b/apertium/__init__.py index cebf6ee..f3b7db8 100644 --- a/apertium/__init__.py +++ b/apertium/__init__.py @@ -62,9 +62,9 @@ def update_path_windows() -> None: pair_paths = ['/usr/share/apertium', '/usr/local/share/apertium'] -analyzers = {} # type: Dict[str, Tuple[str, str]] -generators = {} # type: Dict[str, Tuple[str, str]] -pairs = {} # type: Dict[str, str] +analyzers: Dict[str, Tuple[str, str]] = {} +generators: Dict[str, Tuple[str, str]] = {} +pairs: Dict[str, str] = {} for pair_path in pair_paths: _update_modes(pair_path) append_pair_path_windows() diff --git a/apertium/analysis/__init__.py b/apertium/analysis/__init__.py index 85c3e1a..edc3840 100644 --- a/apertium/analysis/__init__.py +++ b/apertium/analysis/__init__.py @@ -19,14 +19,14 @@ class Analyzer: Args: lang (str) """ - self.analyzer_cmds = {} # type: Dict[str, List[List[str]]] - self.lang = to_alpha3_code(lang) # type: str + self.analyzer_cmds: Dict[str, List[List[str]]] = {} + self.lang: str = to_alpha3_code(lang) if self.lang not in apertium.analyzers: raise apertium.ModeNotInstalled(self.lang) else: self.path, self.mode = apertium.analyzers[self.lang] - def _get_commands(self): # type: (Analyzer) -> List[List[str]] + def _get_commands(self) -> List[List[str]]: """ Returns: List[List[str]] @@ -38,7 +38,7 @@ class Analyzer: return self.analyzer_cmds[self.lang] @staticmethod - def _postproc_text(result): # type: (str) -> List[LexicalUnit] + def _postproc_text(result: str) -> List[LexicalUnit]: """ Postprocesses the input @@ -51,7 +51,7 @@ class Analyzer: lexical_units = list(parse(result)) return lexical_units - def analyze(self, in_text, formatting='txt'): # type: (Analyzer, str, str) -> List[LexicalUnit] + def analyze(self, in_text: str, formatting: str = 'txt') -> List[LexicalUnit]: """ Runs apertium to analyze the input @@ -68,7 +68,7 @@ class Analyzer: return self._postproc_text(result) -def analyze(lang, in_text, formatting='txt'): # type: (str, str, str) -> List[LexicalUnit] +def analyze(lang: str, in_text: str, formatting: str = 'txt') -> List[LexicalUnit]: """ Args: lang (str) diff --git a/apertium/generation/__init__.py b/apertium/generation/__init__.py index 2707ee9..81bece7 100644 --- a/apertium/generation/__init__.py +++ b/apertium/generation/__init__.py @@ -16,8 +16,8 @@ class Generator: Args: lang (str) """ - self.generator_cmds = {} # type: Dict[str, List[List[str]]] - self.lang = lang # type: str + self.generator_cmds: Dict[str, List[List[str]]] = {} + self.lang: str = lang def _get_commands(self) -> List[List[str]]: """ diff --git a/apertium/translation/__init__.py b/apertium/translation/__init__.py index de9346e..7c9caea 100644 --- a/apertium/translation/__init__.py +++ b/apertium/translation/__init__.py @@ -20,11 +20,11 @@ class Translator: l1 (str) l2 (str) """ - self.translation_cmds = {} # type: Dict[Tuple[str, str], List[List[str]]] + self.translation_cmds: Dict[Tuple[str, str], List[List[str]]] = {} # type self.l1 = l1 self.l2 = l2 - def _get_commands(self, l1, l2): # type: (Translator, str, str) -> List[List[str]] + def _get_commands(self, l1: str, l2: str) -> List[List[str]]: """ Args: l1 (str) @@ -59,7 +59,7 @@ class Translator: return deformat, reformat - def _check_ret_code(self, proc): # type: (Translator, Popen) -> None + def _check_ret_code(self, proc: Popen) -> None: """ Args: proc (Popen) @@ -67,7 +67,7 @@ class Translator: if proc.returncode != 0: raise CalledProcessError() # type: ignore - def _validate_formatters(self, deformat, reformat): # type: (Translator, Optional[str], Optional[str]) -> Tuple[Union[str, object], Union[str, object]] + def _validate_formatters(self, deformat: Optional[str], reformat: Optional[str]) -> Tuple[Union[str, object], Union[str, object]]: """ Args: deformat (Optional[str]) @@ -76,7 +76,7 @@ class Translator: Returns: Tuple[Union[str, object], Union[str, object]] """ - def valid1(elt, lst): # type: (Optional[str], List[object]) -> Union[str, object] + def valid1(elt: Optional[str], lst: List[object]) -> Union[str, object]: """ Args: elt (Optional[str]) @@ -105,7 +105,7 @@ class Translator: ] return valid1(deformat, deformatters), valid1(reformat, reformatters) - def _get_deformat(self, deformat, text): # type: (Translator, str, str) -> str + def _get_deformat(self, deformat: str, text: str) -> str: """ Args: deformat (str) @@ -125,7 +125,7 @@ class Translator: res = str(deformatted) return res - def _get_reformat(self, reformat, text): # type: (Translator, str, str) -> str + def _get_reformat(self, reformat: str, text: str) -> str: """ Args: reformat (str) diff --git a/apertium/utils.py b/apertium/utils.py index 6ef8ff1..7dd10c9 100644 --- a/apertium/utils.py +++ b/apertium/utils.py @@ -4,7 +4,7 @@ from typing import List import apertium # noqa: F401 from apertium.iso639 import iso_639_codes -from apertium import lttoolbox +from apertium import lttoolbox iso639_codes_inverse = {v: k for k, v in iso_639_codes.items()}