Skip to content

Commit 63755b8

Browse files
committed
chore: Tweaks to satisfy mypy
1 parent ec4d5bf commit 63755b8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

rdflib/plugins/sparql/algebra.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ def translateGroupGraphPattern(graphPattern: CompValue) -> CompValue:
335335
"""
336336

337337
if graphPattern.name == "SubSelect":
338-
return ToMultiSet(translate(graphPattern)[0])
338+
# The first output from translate cannot be None for a subselect query
339+
# as it can only be None for certain DESCRIBE queries.
340+
# type error: Argument 1 to "ToMultiSet" has incompatible type "Optional[CompValue]";
341+
# expected "Union[List[Dict[Variable, str]], CompValue]"
342+
return ToMultiSet(translate(graphPattern)[0]) # type: ignore[arg-type]
339343

340344
if not graphPattern.part:
341345
graphPattern.part = [] # empty { }

rdflib/plugins/sparql/evaluate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,8 @@ def evalConstructQuery(ctx: QueryContext, query) -> Dict[str, Union[str, Graph]]
588588
def evalDescribeQuery(ctx: QueryContext, query) -> Dict[str, Union[str, Graph]]:
589589
# Create a result graph and bind namespaces from the graph being queried
590590
graph = Graph()
591-
for pfx, ns in ctx.graph.namespaces():
591+
# type error: Item "None" of "Optional[Graph]" has no attribute "namespaces"
592+
for pfx, ns in ctx.graph.namespaces(): # type: ignore[union-attr]
592593
graph.bind(pfx, ns)
593594

594595
to_describe = set()
@@ -609,7 +610,8 @@ def evalDescribeQuery(ctx: QueryContext, query) -> Dict[str, Union[str, Graph]]:
609610

610611
# Get a CBD for all resources identified to describe
611612
for resource in to_describe:
612-
graph += ctx.graph.cbd(resource)
613+
# type error: Item "None" of "Optional[Graph]" has no attribute "cbd"
614+
graph += ctx.graph.cbd(resource) # type: ignore[union-attr]
613615

614616
res: Dict[str, Union[str, Graph]] = {}
615617
res["type_"] = "DESCRIBE"

test/test_sparql/test_sparql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ def test_queries(
946946
)
947947
def test_sparql_describe(
948948
query_string: str,
949-
expected_subjects: set[Identifier],
949+
expected_subjects: set,
950950
expected_size: int,
951951
rdfs_graph: Graph,
952952
) -> None:

0 commit comments

Comments
 (0)