Skip to content

Commit 1c45ec4

Browse files
authored
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.
1 parent 081a974 commit 1c45ec4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

rdflib/graph.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@
105105
_TripleOrQuadSelectorType = Union["_TripleSelectorType", "_QuadSelectorType"]
106106
_TriplePathType = Tuple["_SubjectType", Path, "_ObjectType"]
107107
_TripleOrTriplePathType = Union["_TripleType", "_TriplePathType"]
108-
# _QuadPathType = Tuple["_SubjectType", Path, "_ObjectType", "_ContextType"]
109-
# _QuadOrQuadPathType = Union["_QuadType", "_QuadPathType"]
110108

111109
_GraphT = TypeVar("_GraphT", bound="Graph")
112110
_ConjunctiveGraphT = TypeVar("_ConjunctiveGraphT", bound="ConjunctiveGraph")
@@ -677,7 +675,7 @@ def __iter__(self) -> Generator["_TripleType", None, None]:
677675
"""Iterates over all triples in the store"""
678676
return self.triples((None, None, None))
679677

680-
def __contains__(self, triple: _TriplePatternType) -> bool:
678+
def __contains__(self, triple: _TripleSelectorType) -> bool:
681679
"""Support for 'triple in graph' syntax"""
682680
for triple in self.triples(triple):
683681
return True
@@ -1979,7 +1977,7 @@ def _spoc(
19791977
c = self._graph(c)
19801978
return s, p, o, c
19811979

1982-
def __contains__(self, triple_or_quad: _TripleOrQuadPatternType) -> bool:
1980+
def __contains__(self, triple_or_quad: _TripleOrQuadSelectorType) -> bool:
19831981
"""Support for 'triple/quad in graph' syntax"""
19841982
s, p, o, c = self._spoc(triple_or_quad)
19851983
for t in self.triples((s, p, o), context=c):
@@ -2753,7 +2751,7 @@ def triples(
27532751
for s1, p1, o1 in graph.triples((s, p, o)):
27542752
yield s1, p1, o1
27552753

2756-
def __contains__(self, triple_or_quad: _TripleOrQuadPatternType) -> bool:
2754+
def __contains__(self, triple_or_quad: _TripleOrQuadSelectorType) -> bool:
27572755
context = None
27582756
if len(triple_or_quad) == 4:
27592757
# type error: Tuple index out of range

0 commit comments

Comments
 (0)