Skip to content

Commit e7d6184

Browse files
authored
More mypy (#451)
* Fix: Correct more mypy errors. * Add: Run type checks on each commit. * Fix: mypy failure on Python 3.8.
1 parent 3a52fbd commit e7d6184

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

.github/workflows/test-on-push.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ jobs:
7878
python -m poetry run python scripts/fetch_core.py
7979
python -m poetry run python scripts/zip_templates.py
8080
81+
- name: Check types
82+
run: |
83+
python -m poetry run mypy --install-types --non-interactive
84+
8185
- name: Test with pytest
8286
run: |
8387
python -m poetry run pytest -v --cov

pretext/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def latex_image(
2222
all_formats: bool = False,
2323
) -> None:
2424
# Dictionary of formats for images based on target
25-
formats = {
25+
formats: Dict[str, List[str]] = {
2626
"pdf": [],
2727
"latex": [],
2828
"html": ["svg"],
@@ -43,7 +43,7 @@ def latex_image(
4343
li := source_xml.xpath("/pretext/*[not(docinfo)]//latex-image"), List
4444
)
4545
and len(li) > 0
46-
and formats[target_format] is not None
46+
and formats[target_format] != []
4747
):
4848
image_output = (output / "latex-image").resolve()
4949
os.makedirs(image_output, exist_ok=True)
@@ -159,7 +159,7 @@ def asymptote(
159159
}
160160
# set overwrite formats to all when appropriate
161161
if all_formats:
162-
formats[target_format] = {key: ["all"] for key in formats[target_format]}
162+
formats[target_format] = ["all"]
163163
# We assume passed paths are absolute.
164164
# parse source so we can check for asymptote.
165165
source_xml = ET.parse(ptxfile)

pretext/templates/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def resource_path(filename: str) -> AbstractContextManager:
1414
# Try except here is to use newer importlib function,
1515
# supported starting with 3.9, and required with 3.11
1616
try:
17-
return ir.as_file(ir.files(resources).joinpath(filename))
17+
# TODO: remove the ignore when Python 3.8 support ends. This fails Python 3.8 type checks, since these functions depend on newer Python versions.
18+
return ir.as_file(ir.files(resources).joinpath(filename)) # type: ignore[attr-defined]
1819
except AttributeError:
1920
return ir.path(resources, filename)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ script_launch_mode = "subprocess"
8080
[tool.mypy]
8181
# See `files <https://mypy.readthedocs.io/en/stable/config_file.html#confval-files>`_.
8282
files = "pretext"
83-
exclude = "^pretext/core/pretext.py"
83+
exclude = "^pretext/core/pretext\\.py$"
8484
check_untyped_defs = true
8585
disallow_untyped_defs = true
8686

0 commit comments

Comments
 (0)