Skip to content

Commit 063177f

Browse files
committed
chore: enable type testing
We run mypy in non-strict mode, for now. But we should strive to annotate the entire codebase.
1 parent 675f3c7 commit 063177f

File tree

8 files changed

+16
-13
lines changed

8 files changed

+16
-13
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ requirements: ## install development environment requirements
7676
test: clean ## run tests in the current virtualenv
7777
pytest
7878

79+
test-types: ## run mypy tests on the whole codebase
80+
mypy --ignore-missing-imports code_annotations/ tests/ test_utils/ setup.py
81+
7982
diff_cover: test ## find diff lines that need test coverage
8083
diff-cover coverage.xml
8184

code_annotations/annotation_errors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
"""
44
from collections import namedtuple
55

6-
AnnotationErrorType = namedtuple(
6+
AnnotationError = namedtuple(
77
"AnnotationError", ["message", "symbol", "description"]
88
)
99

10-
# The TYPES list should contain all AnnotationErrorType instances. This list can then be parsed by others, for instance
10+
# The TYPES list should contain all AnnotationError instances. This list can then be parsed by others, for instance
1111
# to expose errors to pylint.
1212
TYPES = []
1313

1414

1515
def add_error_type(message, symbol, description):
1616
"""
17-
Create an AnnotationErrorType instance and add it to TYPES.
17+
Create an AnnotationError instance and add it to TYPES.
1818
"""
19-
error_type = AnnotationErrorType(
19+
error_type = AnnotationError(
2020
message,
2121
symbol,
2222
description,

code_annotations/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def __init__(self, config):
327327
self.echo = self.config.echo
328328
# errors contains formatted error messages
329329
self.errors = []
330-
# annotation_errors contains (annotation, AnnotationErrorType, args) tuples
330+
# annotation_errors contains (annotation, AnnotationError, args) tuples
331331
# This attribute may be parsed by 3rd-parties, such as edx-lint.
332332
self.annotation_errors = []
333333

@@ -549,7 +549,7 @@ def _add_annotation_error(self, annotation, error_type, args=None):
549549
550550
Args:
551551
annotation: A single annotation dict found in search()
552-
error_type (annotation_errors.AnnotationErrorType): error type from which the error message will be
552+
error_type (annotation_errors.AnnotationError): error type from which the error message will be
553553
generated.
554554
args (tuple): arguments for error message formatting.
555555
"""

code_annotations/contrib/sphinx/extensions/openedx_events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class OpenedxEvents(SphinxDirective):
5353

5454
required_arguments = 0
5555
optional_arguments = 0
56-
option_spec = {}
5756

5857
def run(self):
5958
"""

code_annotations/extensions/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AnnotationExtension(metaclass=ABCMeta):
1212
Abstract base class that annotation extensions will inherit from.
1313
"""
1414

15-
extension_name = None
15+
extension_name: str | None = None
1616

1717
def __init__(self, config, echo):
1818
"""
@@ -40,7 +40,7 @@ class SimpleRegexAnnotationExtension(AnnotationExtension, metaclass=ABCMeta):
4040

4141
# These are the language-specific comment definitions that are defined in the child classes. See the
4242
# Javascript and Python extensions for examples.
43-
lang_comment_definition = None
43+
lang_comment_definition: dict[str, str] | None = None
4444

4545
# This format string/regex finds all comments in the file. The format tokens will be replaced with the
4646
# language-specific comment definitions defined in the sub-classes.

code_annotations/py.typed

Whitespace-only changes.

tests/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class FakeConfig:
3939
Simple config for testing without reading a config file.
4040
"""
4141

42-
annotations = {}
43-
annotation_regexes = []
44-
annotation_tokens = []
45-
groups = []
42+
annotations: dict[str, str] = {}
43+
annotation_regexes: list[str] = []
44+
annotation_tokens: list[str] = []
45+
groups: list[str] = []
4646
echo = VerboseEcho()
4747

4848

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ deps =
5151
-r{toxinidir}/requirements/quality.txt
5252
commands =
5353
pylint code_annotations tests test_utils setup.py
54+
make test-types
5455
pycodestyle code_annotations tests setup.py
5556
pydocstyle code_annotations tests setup.py
5657
isort --check-only --diff tests test_utils code_annotations setup.py

0 commit comments

Comments
 (0)