From 91a198581136ada436418fa10f356e47d7ba8d5b Mon Sep 17 00:00:00 2001 From: Bryan Forbes Date: Sun, 1 Dec 2019 20:50:00 -0600 Subject: [PATCH] Add typings --- mypy.ini | 16 ++++++++++++++++ pysblgnt/__init__.py | 22 ++++++++++++++++++---- setup.py | 2 ++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..d757794 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,16 @@ +[mypy] +incremental = True +warn_unused_configs = True +disallow_any_generics = True +disallow_subclassing_any = True +disallow_untyped_calls = True +disallow_untyped_defs = True +disallow_incomplete_defs = True +check_untyped_defs = True +disallow_untyped_decorators = True +no_implicit_optional = True +warn_redundant_casts = True +warn_unused_ignores = True +warn_return_any = True +no_implicit_reexport = True +disallow_any_unimported = True diff --git a/pysblgnt/__init__.py b/pysblgnt/__init__.py index c07bde4..ea7e3da 100644 --- a/pysblgnt/__init__.py +++ b/pysblgnt/__init__.py @@ -1,7 +1,21 @@ import os.path +from typing import Any, Iterator, cast +from typing_extensions import TypedDict -def morphgnt_filename(book_num): +BaseRow = TypedDict('BaseRow', { "ccat-pos": str, "ccat-parse": str }) + + +class MorphRow(BaseRow): + bcv: str + robinson: str + text: str + word: str + norm: str + lemma: str + + +def morphgnt_filename(book_num: int) -> str: """ return the MorphGNT filename of the given book number. @@ -16,7 +30,7 @@ def morphgnt_filename(book_num): ) -def morphgnt_rows(book_num): +def morphgnt_rows(book_num: int) -> Iterator[MorphRow]: """ yield a dict for each MorphGNT/SBLGNT row in the given book number. """ @@ -27,10 +41,10 @@ def morphgnt_rows(book_num): with open(filename) as f: for line in f: - yield dict(zip( + yield cast(MorphRow, dict(zip( ( "bcv", "ccat-pos", "ccat-parse", "robinson", "text", "word", "norm", "lemma" ), line.strip().split() - )) + ))) diff --git a/setup.py b/setup.py index f7eecfc..758d0b1 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,8 @@ url="https://github.com/morphgnt/py-sblgnt", author="James Tauber", author_email="jtauber@jtauber.com", + python_requires=">=3.6", + install_requires=["typing_extensions>=3.7.4"], packages=["pysblgnt"], package_data={"": ["sblgnt/*.txt"]}, )