diff options
author | Elliot Ford <elliot.ford@astrazeneca.com> | 2023-04-03 09:29:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 10:29:03 +0200 |
commit | 1c45ec4e46d6257011b6e55888c5efb8470e4049 (patch) | |
tree | e7890ff72438a9945163a637cb7648bcc1f188d3 | |
parent | 081a974bc91d31d55087f3c6c516b95960ae8bfa (diff) | |
download | rdflib-1c45ec4e46d6257011b6e55888c5efb8470e4049.tar.gz |
fix: widen `Graph.__contains__` type-hints to accept `Path` values (#2323)
Change the type-hints for `Graph.__contains__` to also accept `Path`
values as the parameter is passed to the `Graph.triples` function,
which accepts `Path` values.
-rw-r--r-- | rdflib/graph.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/rdflib/graph.py b/rdflib/graph.py index 4a96e6d3..809241df 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -105,8 +105,6 @@ _QuadSelectorType = Tuple[ _TripleOrQuadSelectorType = Union["_TripleSelectorType", "_QuadSelectorType"] _TriplePathType = Tuple["_SubjectType", Path, "_ObjectType"] _TripleOrTriplePathType = Union["_TripleType", "_TriplePathType"] -# _QuadPathType = Tuple["_SubjectType", Path, "_ObjectType", "_ContextType"] -# _QuadOrQuadPathType = Union["_QuadType", "_QuadPathType"] _GraphT = TypeVar("_GraphT", bound="Graph") _ConjunctiveGraphT = TypeVar("_ConjunctiveGraphT", bound="ConjunctiveGraph") @@ -677,7 +675,7 @@ class Graph(Node): """Iterates over all triples in the store""" return self.triples((None, None, None)) - def __contains__(self, triple: _TriplePatternType) -> bool: + def __contains__(self, triple: _TripleSelectorType) -> bool: """Support for 'triple in graph' syntax""" for triple in self.triples(triple): return True @@ -1979,7 +1977,7 @@ class ConjunctiveGraph(Graph): c = self._graph(c) return s, p, o, c - def __contains__(self, triple_or_quad: _TripleOrQuadPatternType) -> bool: + def __contains__(self, triple_or_quad: _TripleOrQuadSelectorType) -> bool: """Support for 'triple/quad in graph' syntax""" s, p, o, c = self._spoc(triple_or_quad) for t in self.triples((s, p, o), context=c): @@ -2753,7 +2751,7 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph): for s1, p1, o1 in graph.triples((s, p, o)): yield s1, p1, o1 - def __contains__(self, triple_or_quad: _TripleOrQuadPatternType) -> bool: + def __contains__(self, triple_or_quad: _TripleOrQuadSelectorType) -> bool: context = None if len(triple_or_quad) == 4: # type error: Tuple index out of range |