Skip to content

Specify Optional parameters in Graph.triples_choices #3075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@
_TripleOrQuadSelectorType = Union["_TripleSelectorType", "_QuadSelectorType"]
_TriplePathType = Tuple["_SubjectType", Path, "_ObjectType"]
_TripleOrTriplePathType = Union["_TripleType", "_TriplePathType"]
_TripleChoiceType = Union[
Tuple[List[_SubjectType], Optional[_PredicateType], Optional[_ObjectType]],
Tuple[Optional[_SubjectType], List[_PredicateType], Optional[_ObjectType]],
Tuple[Optional[_SubjectType], Optional[_PredicateType], List[_ObjectType]],
]

_GraphT = TypeVar("_GraphT", bound="Graph")
_ConjunctiveGraphT = TypeVar("_ConjunctiveGraphT", bound="ConjunctiveGraph")
Expand Down Expand Up @@ -994,11 +999,7 @@ def predicate_objects(

def triples_choices(
self,
triple: Union[
Tuple[List[_SubjectType], _PredicateType, _ObjectType],
Tuple[_SubjectType, List[_PredicateType], _ObjectType],
Tuple[_SubjectType, _PredicateType, List[_ObjectType]],
],
triple: _TripleChoiceType,
context: Optional[_ContextType] = None,
) -> Generator[_TripleType, None, None]:
subject, predicate, object_ = triple
Expand Down Expand Up @@ -2196,11 +2197,7 @@ def quads(

def triples_choices(
self,
triple: Union[
Tuple[List[_SubjectType], _PredicateType, _ObjectType],
Tuple[_SubjectType, List[_PredicateType], _ObjectType],
Tuple[_SubjectType, _PredicateType, List[_ObjectType]],
],
triple: _TripleChoiceType,
context: Optional[_ContextType] = None,
) -> Generator[_TripleType, None, None]:
"""Iterate over all the triples in the entire conjunctive graph"""
Expand Down Expand Up @@ -2946,11 +2943,7 @@ def __isub__(self: _GraphT, other: Iterable[_TripleType]) -> NoReturn:

def triples_choices(
self,
triple: Union[
Tuple[List[_SubjectType], _PredicateType, _ObjectType],
Tuple[_SubjectType, List[_PredicateType], _ObjectType],
Tuple[_SubjectType, _PredicateType, List[_ObjectType]],
],
triple: _TripleChoiceType,
context: Optional[_ContextType] = None,
) -> Generator[_TripleType, None, None]:
subject, predicate, object_ = triple
Expand Down
7 changes: 2 additions & 5 deletions rdflib/plugins/stores/sparqlstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
_TripleType,
_ContextType,
_QuadType,
_TripleChoiceType,
_TriplePatternType,
_SubjectType,
_PredicateType,
Expand Down Expand Up @@ -367,11 +368,7 @@ def triples( # type: ignore[override]

def triples_choices(
self,
_: Tuple[
Union[_SubjectType, List[_SubjectType]],
Union[_PredicateType, List[_PredicateType]],
Union[_ObjectType, List[_ObjectType]],
],
_: _TripleChoiceType,
context: Optional[_ContextType] = None,
) -> Generator[
Tuple[
Expand Down
7 changes: 2 additions & 5 deletions rdflib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
_PredicateType,
_QuadType,
_SubjectType,
_TripleChoiceType,
_TriplePatternType,
_TripleType,
)
Expand Down Expand Up @@ -281,11 +282,7 @@ def remove(

def triples_choices(
self,
triple: Union[
Tuple[List[_SubjectType], _PredicateType, _ObjectType],
Tuple[_SubjectType, List[_PredicateType], _ObjectType],
Tuple[_SubjectType, _PredicateType, List[_ObjectType]],
],
triple: _TripleChoiceType,
context: Optional[_ContextType] = None,
) -> Generator[
Tuple[
Expand Down