Skip to content

check mypy #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include src/django_idom/py.typed
recursive-include src/django_idom/static *
recursive-include src/django_idom/templates *.html
8 changes: 8 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test(session: Session) -> None:
"""Run the complete test suite"""
session.install("--upgrade", "pip", "setuptools", "wheel")
session.notify("test_suite", posargs=session.posargs)
session.notify("test_types")
session.notify("test_style")


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


@nox.session
def test_types(session: Session) -> None:
install_requirements_file(session, "check-types")
install_requirements_file(session, "pkg-deps")
session.run("mypy", "--show-error-codes", "src/django_idom", "tests/test_app")


@nox.session
def test_style(session: Session) -> None:
"""Check that style guidelines are being followed"""
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ ensure_newline_before_comments = "True"
include_trailing_comma = "True"
line_length = 88
lines_after_imports = 2

[tool.mypy]
ignore_missing_imports = "True"
warn_unused_configs = "True"
warn_redundant_casts = "True"
warn_unused_ignores = "True"
2 changes: 2 additions & 0 deletions requirements/check-types.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mypy
django-stubs[compatible-mypy]
2 changes: 1 addition & 1 deletion src/django_idom/http/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
urlpatterns = [
path(
"web_module/<path:file>",
views.web_modules_file,
views.web_modules_file, # type: ignore[arg-type]
name="web_modules",
)
]
1 change: 1 addition & 0 deletions src/django_idom/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Marker file for PEP 561
19 changes: 10 additions & 9 deletions src/django_idom/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import contextlib
import logging
import os
import re
from fnmatch import fnmatch
from importlib import import_module
from typing import Set

from django.template import engines
from django.utils.encoding import smart_str
Expand Down Expand Up @@ -68,9 +69,9 @@ def _get_loaders(self):
loaders.append(loader)
return loaders

def _get_paths(self) -> Set:
def _get_paths(self) -> set[str]:
"""Obtains a set of all template directories."""
paths = set()
paths: set[str] = set()
for loader in self._get_loaders():
with contextlib.suppress(ImportError, AttributeError, TypeError):
module = import_module(loader.__module__)
Expand All @@ -80,12 +81,12 @@ def _get_paths(self) -> Set:
paths.update(smart_str(origin) for origin in get_template_sources(""))
return paths

def _get_templates(self, paths: Set) -> Set:
def _get_templates(self, paths: set[str]) -> set[str]:
"""Obtains a set of all HTML template paths."""
extensions = [".html"]
templates = set()
templates: set[str] = set()
for path in paths:
for root, dirs, files in os.walk(path, followlinks=False):
for root, _, files in os.walk(path, followlinks=False):
templates.update(
os.path.join(root, name)
for name in files
Expand All @@ -95,9 +96,9 @@ def _get_templates(self, paths: Set) -> Set:

return templates

def _get_components(self, templates: Set) -> Set:
def _get_components(self, templates: set[str]) -> set[str]:
"""Obtains a set of all IDOM components by parsing HTML templates."""
components = set()
components: set[str] = set()
for template in templates:
with contextlib.suppress(Exception):
with open(template, "r", encoding="utf-8") as template_file:
Expand All @@ -118,7 +119,7 @@ def _get_components(self, templates: Set) -> Set:
)
return components

def _register_components(self, components: Set) -> None:
def _register_components(self, components: set[str]) -> None:
"""Registers all IDOM components in an iterable."""
for component in components:
try:
Expand Down