Update Graph.triples() signature, and rename method variables
`mypy` was confused by some of the variable name re-use and/or
re-definition.
This patch also highlights that `Path`s can be yielded in the predicate
position, which has further downstream consequences in `graph.py` and in
the `Store` class.
References:
*
@@ -457,19 +457,19 @@ class Graph(Node):
triple: Tuple[
Optional[IdentifiedNode], Union[None, Path, IdentifiedNode], Optional[Node]
],
- ) -> Iterable[Tuple[IdentifiedNode, IdentifiedNode, Node]]:
+ ) -> Iterable[Tuple[IdentifiedNode, Union[IdentifiedNode, Path], Node]]:
"""Generator over the triple store
Returns triples that match the given triple pattern. If triple pattern
does not provide a context, all contexts will be searched.
"""
- s, p, o = triple
- if isinstance(p, Path):
- for _s, _o in p.eval(self, s, o):
- yield _s, p, _o
+ (s0, p0, o0) = triple
+ if isinstance(p0, Path):
+ for s1, o1 in p0.eval(self, s0, o0):
+ yield s1, p0, o1
else:
- for (s, p, o), cg in self.__store.triples((s, p, o), context=self):
- yield s, p, o
+ for (s2, p2, o2), cg in self.__store.triples(triple, context=self):
+ yield s2, p2, o2
def __getitem__(self, item):
"""
