Skip to content

Commit 8a4d572

Browse files
authored
check mypy (#95)
1 parent 1e571ff commit 8a4d572

File tree

7 files changed

+29
-10
lines changed

7 files changed

+29
-10
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
include src/django_idom/py.typed
12
recursive-include src/django_idom/static *
23
recursive-include src/django_idom/templates *.html

noxfile.py

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test(session: Session) -> None:
3737
"""Run the complete test suite"""
3838
session.install("--upgrade", "pip", "setuptools", "wheel")
3939
session.notify("test_suite", posargs=session.posargs)
40+
session.notify("test_types")
4041
session.notify("test_style")
4142

4243

@@ -60,6 +61,13 @@ def test_suite(session: Session) -> None:
6061
session.run("python", "manage.py", "test", *posargs)
6162

6263

64+
@nox.session
65+
def test_types(session: Session) -> None:
66+
install_requirements_file(session, "check-types")
67+
install_requirements_file(session, "pkg-deps")
68+
session.run("mypy", "--show-error-codes", "src/django_idom", "tests/test_app")
69+
70+
6371
@nox.session
6472
def test_style(session: Session) -> None:
6573
"""Check that style guidelines are being followed"""

pyproject.toml

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ ensure_newline_before_comments = "True"
1010
include_trailing_comma = "True"
1111
line_length = 88
1212
lines_after_imports = 2
13+
14+
[tool.mypy]
15+
ignore_missing_imports = "True"
16+
warn_unused_configs = "True"
17+
warn_redundant_casts = "True"
18+
warn_unused_ignores = "True"

requirements/check-types.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mypy
2+
django-stubs[compatible-mypy]

src/django_idom/http/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
urlpatterns = [
99
path(
1010
"web_module/<path:file>",
11-
views.web_modules_file,
11+
views.web_modules_file, # type: ignore[arg-type]
1212
name="web_modules",
1313
)
1414
]

src/django_idom/py.typed

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Marker file for PEP 561

src/django_idom/utils.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from __future__ import annotations
2+
13
import contextlib
24
import logging
35
import os
46
import re
57
from fnmatch import fnmatch
68
from importlib import import_module
7-
from typing import Set
89

910
from django.template import engines
1011
from django.utils.encoding import smart_str
@@ -68,9 +69,9 @@ def _get_loaders(self):
6869
loaders.append(loader)
6970
return loaders
7071

71-
def _get_paths(self) -> Set:
72+
def _get_paths(self) -> set[str]:
7273
"""Obtains a set of all template directories."""
73-
paths = set()
74+
paths: set[str] = set()
7475
for loader in self._get_loaders():
7576
with contextlib.suppress(ImportError, AttributeError, TypeError):
7677
module = import_module(loader.__module__)
@@ -80,12 +81,12 @@ def _get_paths(self) -> Set:
8081
paths.update(smart_str(origin) for origin in get_template_sources(""))
8182
return paths
8283

83-
def _get_templates(self, paths: Set) -> Set:
84+
def _get_templates(self, paths: set[str]) -> set[str]:
8485
"""Obtains a set of all HTML template paths."""
8586
extensions = [".html"]
86-
templates = set()
87+
templates: set[str] = set()
8788
for path in paths:
88-
for root, dirs, files in os.walk(path, followlinks=False):
89+
for root, _, files in os.walk(path, followlinks=False):
8990
templates.update(
9091
os.path.join(root, name)
9192
for name in files
@@ -95,9 +96,9 @@ def _get_templates(self, paths: Set) -> Set:
9596

9697
return templates
9798

98-
def _get_components(self, templates: Set) -> Set:
99+
def _get_components(self, templates: set[str]) -> set[str]:
99100
"""Obtains a set of all IDOM components by parsing HTML templates."""
100-
components = set()
101+
components: set[str] = set()
101102
for template in templates:
102103
with contextlib.suppress(Exception):
103104
with open(template, "r", encoding="utf-8") as template_file:
@@ -118,7 +119,7 @@ def _get_components(self, templates: Set) -> Set:
118119
)
119120
return components
120121

121-
def _register_components(self, components: Set) -> None:
122+
def _register_components(self, components: set[str]) -> None:
122123
"""Registers all IDOM components in an iterable."""
123124
for component in components:
124125
try:

0 commit comments

Comments
 (0)