feat: add type hints for rdflib.store and rdflib.plugins.stores · RDFLib/rdflib@16d9618 (original) (raw)

`@@ -42,14 +42,15 @@

`

42

42

`_SubjectType = Node

`

43

43

`_PredicateType = Node

`

44

44

`_ObjectType = Node

`

``

45

`+

_ContextIdentifierType = Node

`

45

46

``

46

47

`_TripleType = Tuple["_SubjectType", "_PredicateType", "_ObjectType"]

`

47

``

`-

_QuadType = Tuple["_SubjectType", "_PredicateType", "_ObjectType", "Graph"]

`

``

48

`+

_QuadType = Tuple["_SubjectType", "_PredicateType", "_ObjectType", "_ContextType"]

`

48

49

`_OptionalQuadType = Tuple[

`

49

``

`-

"_SubjectType", "_PredicateType", "_ObjectType", Optional["Graph"]

`

``

50

`+

"_SubjectType", "_PredicateType", "_ObjectType", Optional["_ContextType"]

`

50

51

`]

`

51

52

`_OptionalIdentifiedQuadType = Tuple[

`

52

``

`-

"_SubjectType", "_PredicateType", "_ObjectType", Optional["Node"]

`

``

53

`+

"_SubjectType", "_PredicateType", "_ObjectType", Optional["_ContextIdentifierType"]

`

53

54

`]

`

54

55

`_TriplePatternType = Tuple[

`

55

56

`Optional["_SubjectType"], Optional["_PredicateType"], Optional["_ObjectType"]

`

`@@ -393,7 +394,7 @@ def store(self) -> Store:

`

393

394

`return self.__store

`

394

395

``

395

396

`@property

`

396

``

`-

def identifier(self) -> Node:

`

``

397

`+

def identifier(self) -> "_ContextIdentifierType":

`

397

398

`return self.__identifier

`

398

399

``

399

400

`@property

`

`@@ -534,9 +535,7 @@ def triples(

`

534

535

`for _s, _o in p.eval(self, s, o):

`

535

536

`yield _s, p, _o

`

536

537

`else:

`

537

``

`-

type error: Argument 1 to "triples" of "Store" has incompatible type "Tuple[Optional[Node], Optional[Node], Optional[Node]]"; expected "Tuple[Optional[IdentifiedNode], Optional[IdentifiedNode], Optional[Node]]"

`

538

``

`-

NOTE on type error: This is because the store typing is too narrow, willbe fixed in subsequent PR.

`

539

``

`-

for (_s, _p, _o), cg in self.__store.triples((s, p, o), context=self): # type: ignore [arg-type]

`

``

538

`+

for (_s, _p, _o), cg in self.__store.triples((s, p, o), context=self):

`

540

539

`yield _s, _p, _o

`

541

540

``

542

541

`def getitem(self, item):

`

`@@ -1384,7 +1383,8 @@ def query(

`

1384

1383

`query_object,

`

1385

1384

`initNs,

`

1386

1385

`initBindings,

`

1387

``

`-

self.default_union and "UNION" or self.identifier,

`

``

1386

`+

type error: Argument 4 to "query" of "Store" has incompatible type "Union[Literal['UNION'], Node]"; expected "Identifier"

`

``

1387

`+

self.default_union and "UNION" or self.identifier, # type: ignore[arg-type]

`

1388

1388

`**kwargs,

`

1389

1389

` )

`

1390

1390

`except NotImplementedError:

`

`@@ -1661,6 +1661,9 @@ def add_to_cbd(uri):

`

1661

1661

`return subgraph

`

1662

1662

``

1663

1663

``

``

1664

`+

_ContextType = Graph

`

``

1665

+

``

1666

+

1664

1667

`class ConjunctiveGraph(Graph):

`

1665

1668

`"""A ConjunctiveGraph is an (unnamed) aggregation of all the named

`

1666

1669

` graphs in a store.

`

`@@ -1868,12 +1871,9 @@ def quads(

`

1868

1871

``

1869

1872

`s, p, o, c = self._spoc(triple_or_quad)

`

1870

1873

``

1871

``

`-

type error: Argument 1 to "triples" of "Store" has incompatible type "Tuple[Optional[Node], Optional[Node], Optional[Node]]"; expected "Tuple[Optional[IdentifiedNode], Optional[IdentifiedNode], Optional[Node]]"

`

1872

``

`-

NOTE on type error: This is because the store typing is too narrow, willbe fixed in subsequent PR.

`

1873

``

`-

for (s, p, o), cg in self.store.triples((s, p, o), context=c): # type: ignore[arg-type]

`

``

1874

`+

for (s, p, o), cg in self.store.triples((s, p, o), context=c):

`

1874

1875

`for ctx in cg:

`

1875

``

`-

type error: Incompatible types in "yield" (actual type "Tuple[Optional[Node], Optional[Node], Optional[Node], Any]", expected type "Tuple[Node, Node, Node, Optional[Graph]]")

`

1876

``

`-

yield s, p, o, ctx # type: ignore[misc]

`

``

1876

`+

yield s, p, o, ctx

`

1877

1877

``

1878

1878

`def triples_choices(self, triple, context=None):

`

1879

1879

`"""Iterate over all the triples in the entire conjunctive graph"""

`

`@@ -1905,7 +1905,8 @@ def contexts(

`

1905

1905

`# the weirdness - see #225

`

1906

1906

`yield context

`

1907

1907

`else:

`

1908

``

`-

yield self.get_context(context)

`

``

1908

`+

type error: Statement is unreachable

`

``

1909

`+

yield self.get_context(context) # type: ignore[unreachable]

`

1909

1910

``

1910

1911

`def get_graph(self, identifier: Union[URIRef, BNode]) -> Union[Graph, None]:

`

1911

1912

`"""Returns the graph identified by given identifier"""

`