Skip to content

Commit

Permalink
Add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanforbes committed Dec 2, 2019
1 parent 904fed0 commit 91a1985
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
16 changes: 16 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -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
22 changes: 18 additions & 4 deletions pysblgnt/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
"""
Expand All @@ -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()
))
)))
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
url="https://github.com/morphgnt/py-sblgnt",
author="James Tauber",
author_email="[email protected]",
python_requires=">=3.6",
install_requires=["typing_extensions>=3.7.4"],
packages=["pysblgnt"],
package_data={"": ["sblgnt/*.txt"]},
)

0 comments on commit 91a1985

Please sign in to comment.