Skip to content

Commit d1ca249

Browse files
committed
Add mypy source review to current state
This patch is to show what is needed to add static type checking with `mypy`. The brunt of the effort is adding `#type: ignore` annotations to `rdflib`. These can be removed once an `rdflib` release with the merged PR 1407 is issued. The additional package in `tests/requirements.txt` pertaining to `dateutil` was reported by `mypy`. DISCLAIMER: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * [AC-211] Add static type checking to CASE-Utilities-Python * RDFLib/rdflib#1407 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 83fd6ed commit d1ca249

File tree

13 files changed

+28
-12
lines changed

13 files changed

+28
-12
lines changed

case_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import warnings
1717

18-
import rdflib.util
18+
import rdflib.util # type: ignore
1919

2020
from . import local_uuid
2121

case_utils/case_file/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import hashlib
2222
import os
2323

24-
import rdflib
24+
import rdflib # type: ignore
2525

2626
import case_utils
2727

case_utils/case_sparql_construct/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import os
2222
import logging
2323

24-
import rdflib.plugins.sparql
24+
import rdflib.plugins.sparql # type: ignore
2525

2626
import case_utils
2727

case_utils/case_sparql_select/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import os
3434
import logging
3535

36-
import pandas as pd
37-
import rdflib.plugins.sparql
36+
import pandas as pd # type: ignore
37+
import rdflib.plugins.sparql # type: ignore
3838

3939
import case_utils
4040

tests/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ all: \
3232
check-case_sparql_construct \
3333
check-case_sparql_select \
3434
check-isomorphic_diff \
35+
check-mypy \
3536
download
3637

3738
.venv.done.log: \
@@ -79,6 +80,7 @@ all-case_sparql_select: \
7980
# These check calls are provided in preferred run-order.
8081
check: \
8182
check-isomorphic_diff \
83+
check-mypy \
8284
check-case_file \
8385
check-case_sparql_construct \
8486
check-case_sparql_select
@@ -116,6 +118,18 @@ check-isomorphic_diff: \
116118
--directory isomorphic_diff \
117119
check
118120

121+
# mypy is called against specific members of the tests directory to avoid descending into the virtual environment.
122+
check-mypy: \
123+
.venv.done.log
124+
source venv/bin/activate \
125+
&& mypy \
126+
$(top_srcdir)/case_utils \
127+
case_file \
128+
case_sparql_construct \
129+
case_utils \
130+
hexbinary \
131+
src
132+
119133
clean:
120134
@$(MAKE) \
121135
--directory case_sparql_select \

tests/case_file/test_case_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717

1818
import pytest
19-
import rdflib.plugins.sparql
19+
import rdflib.plugins.sparql # type: ignore
2020

2121
_logger = logging.getLogger(os.path.basename(__file__))
2222

tests/case_sparql_construct/test_case_sparql_construct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# We would appreciate acknowledgement if the software is used.
1313

14-
import rdflib.plugins.sparql
14+
import rdflib.plugins.sparql # type: ignore
1515

1616
import case_utils
1717

tests/case_utils/test_guess_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# We would appreciate acknowledgement if the software is used.
1313

1414
import pytest
15-
import rdflib
15+
import rdflib # type: ignore
1616

1717
import case_utils
1818

tests/hexbinary/test_hexbinary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import os
5151

5252
import pytest
53-
import rdflib.plugins.sparql
53+
import rdflib.plugins.sparql # type: ignore
5454

5555
_logger = logging.getLogger(os.path.basename(__file__))
5656

tests/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
PyLD
2+
mypy
23
pytest
34
python-dateutil
5+
types-python-dateutil

tests/src/compact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import os
2525
import json
2626

27-
import pyld
27+
import pyld # type: ignore
2828

2929
_logger = logging.getLogger(os.path.basename(__file__))
3030

tests/src/glom_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
__version__ = "0.1.0"
1919

20-
import rdflib
20+
import rdflib # type: ignore
2121

2222
import case_utils
2323

tests/src/isomorphic_diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import os
3535
import sys
3636

37-
import rdflib.compare
37+
import rdflib.compare # type: ignore
3838

3939
import case_utils
4040

0 commit comments

Comments
 (0)