Skip to content

Commit 42000c9

Browse files
committed
Add type signatures required by mypy --strict
One more `# type: ignore` was added while awaiting rdflib PR #1407. These were all identified by adding the `--strict` flag to mypy for a run. I will leave it up for future discussion whether to use that flag, especially to wait for PR 1407 and to see if too much work would be induced versus runtime safety improvements. 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 7fb54ef commit 42000c9

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

case_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def guess_format(
2626
) -> typing.Optional[str]:
2727
warnings.warn("The functionality in case_utils.guess_format is now upstream. Please revise your code to use rdflib.util.guess_format. The function arguments remain the same. case_utils.guess_format will be removed in case_utils 0.4.0.", DeprecationWarning)
2828

29-
return rdflib.util.guess_format(fpath, fmap)
29+
return rdflib.util.guess_format(fpath, fmap) # type: ignore

tests/case_file/test_case_file.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
SRCDIR = os.path.dirname(__file__)
3939

4040
def load_graph(
41-
filename
41+
filename : str
4242
) -> rdflib.Graph:
4343
in_graph = rdflib.Graph()
4444
in_graph.parse(filename)
@@ -52,7 +52,9 @@ def graph_case_file() -> rdflib.Graph:
5252
def graph_case_file_disable_hashes() -> rdflib.Graph:
5353
return load_graph(os.path.join(SRCDIR, "sample.txt-disable_hashes.ttl"))
5454

55-
def test_confirm_hashes(graph_case_file) -> None:
55+
def test_confirm_hashes(
56+
graph_case_file : rdflib.Graph
57+
) -> None:
5658
expected = {
5759
"MD5": "098F6BCD4621D373CADE4E832627B4F6",
5860
"SHA1": "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3",
@@ -93,7 +95,10 @@ def test_confirm_hashes(graph_case_file) -> None:
9395

9496
assert expected == computed
9597

96-
def test_confirm_mtime(graph_case_file, graph_case_file_disable_hashes) -> None:
98+
def test_confirm_mtime(
99+
graph_case_file : rdflib.Graph,
100+
graph_case_file_disable_hashes : rdflib.Graph
101+
) -> None:
97102
query_confirm_mtime = """
98103
SELECT ?nFile
99104
WHERE {

tests/case_sparql_construct/test_case_sparql_construct.py

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

1818
import case_utils
1919

20-
def _test_templates_with_blank_nodes_result(filename) -> None:
20+
def _test_templates_with_blank_nodes_result(
21+
filename : str
22+
) -> None:
2123
ground_truth_positive = {
2224
("Alice", "Hacker"),
2325
("Bob", "Hacker")

tests/hexbinary/test_hexbinary.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ def test_rdflib_literal_topython_hexbinarycanonical() -> None:
263263

264264
assert l_hb_uppercase.toPython() == l_hbc_uppercase.toPython()
265265

266-
def _query_all_value_matches(graph) -> typing.Set[str]:
266+
def _query_all_value_matches(
267+
graph : rdflib.Graph
268+
) -> typing.Set[str]:
267269
"""
268270
Return set of all node names (as strings) that have a matching value, where
269271
"matching" is determined by the SPARQL engine's type and data coercions.

tests/src/compact.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import logging
2424
import os
2525
import json
26+
import typing
2627

2728
import pyld # type: ignore
2829

@@ -38,7 +39,9 @@ def main() -> None:
3839

3940
# Grab the first occurrence of every key.
4041
total_context = dict()
41-
def _accrue_local_context(doc_object):
42+
def _accrue_local_context(
43+
doc_object : typing.Dict[str, typing.Any]
44+
) -> None:
4245
local_context = doc_object.get("@context", dict())
4346
for key in local_context.keys():
4447
if not key in total_context:

tests/src/isomorphic_diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def main() -> None:
7070
if i1 == i2:
7171
sys.exit(0)
7272

73-
def _report(diff_symbol, graph):
73+
def _report(
74+
diff_symbol : str,
75+
graph : rdflib.Graph
76+
) -> None:
7477
"""
7578
This function copied in spirit from:
7679
https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#module-rdflib.compare

0 commit comments

Comments
 (0)