104
104
Union ,
105
105
)
106
106
107
- from rdflib .graph import ConjunctiveGraph , Graph , ReadOnlyGraphAggregate
107
+ from rdflib .graph import ConjunctiveGraph , Graph , ReadOnlyGraphAggregate , _TripleType
108
108
from rdflib .term import BNode , IdentifiedNode , Node , URIRef
109
109
110
110
if TYPE_CHECKING :
@@ -281,7 +281,6 @@ def copy(self):
281
281
)
282
282
283
283
284
- _TripleT = List [Node ]
285
284
_HashT = Callable [[], "HASH" ]
286
285
287
286
@@ -326,7 +325,9 @@ def _initial_color(self) -> List[Color]:
326
325
self ._neighbors [p ].add (p )
327
326
if len (bnodes ) > 0 :
328
327
return [Color (list (bnodes ), self .hashfunc , hash_cache = self ._hash_cache )] + [
329
- Color ([x ], self .hashfunc , x , hash_cache = self ._hash_cache )
328
+ # type error: List item 0 has incompatible type "Union[IdentifiedNode, Literal]"; expected "IdentifiedNode"
329
+ # type error: Argument 3 to "Color" has incompatible type "Union[IdentifiedNode, Literal]"; expected "Tuple[Tuple[Union[int, str], URIRef, Union[int, str]], ...]"
330
+ Color ([x ], self .hashfunc , x , hash_cache = self ._hash_cache ) # type: ignore[list-item, arg-type]
330
331
for x in others
331
332
]
332
333
else :
@@ -521,7 +522,7 @@ def canonical_triples(self, stats: Optional[Stats] = None):
521
522
522
523
def _canonicalize_bnodes (
523
524
self ,
524
- triple : Tuple [ IdentifiedNode , IdentifiedNode , Node ] ,
525
+ triple : "_TripleType" ,
525
526
labels : Dict [Node , str ],
526
527
):
527
528
for term in triple :
@@ -531,7 +532,7 @@ def _canonicalize_bnodes(
531
532
yield term
532
533
533
534
534
- def to_isomorphic (graph ) :
535
+ def to_isomorphic (graph : Graph ) -> IsomorphicGraph :
535
536
if isinstance (graph , IsomorphicGraph ):
536
537
return graph
537
538
result = IsomorphicGraph ()
@@ -541,7 +542,7 @@ def to_isomorphic(graph):
541
542
return result
542
543
543
544
544
- def isomorphic (graph1 , graph2 ) :
545
+ def isomorphic (graph1 : Graph , graph2 : Graph ) -> bool :
545
546
"""Compare graph for equality.
546
547
547
548
Uses an algorithm to compute unique hashes which takes bnodes into account.
@@ -577,7 +578,9 @@ def isomorphic(graph1, graph2):
577
578
return gd1 == gd2
578
579
579
580
580
- def to_canonical_graph (g1 , stats = None ):
581
+ def to_canonical_graph (
582
+ g1 : Graph , stats : Optional [Stats ] = None
583
+ ) -> ReadOnlyGraphAggregate :
581
584
"""Creates a canonical, read-only graph.
582
585
583
586
Creates a canonical, read-only graph where all bnode id:s are based on
@@ -588,7 +591,7 @@ def to_canonical_graph(g1, stats=None):
588
591
return ReadOnlyGraphAggregate ([graph ])
589
592
590
593
591
- def graph_diff (g1 , g2 ) :
594
+ def graph_diff (g1 : Graph , g2 : Graph ) -> Tuple [ Graph , Graph , Graph ] :
592
595
"""Returns three sets of triples: "in both", "in first" and "in second"."""
593
596
# bnodes have deterministic values in canonical graphs:
594
597
cg1 = to_canonical_graph (g1 )
@@ -602,7 +605,7 @@ def graph_diff(g1, g2):
602
605
_MOCK_BNODE = BNode ()
603
606
604
607
605
- def similar (g1 , g2 ):
608
+ def similar (g1 : Graph , g2 : Graph ):
606
609
"""Checks if the two graphs are "similar".
607
610
608
611
Checks if the two graphs are "similar", by comparing sorted triples where
@@ -615,12 +618,12 @@ def similar(g1, g2):
615
618
return all (t1 == t2 for (t1 , t2 ) in _squashed_graphs_triples (g1 , g2 ))
616
619
617
620
618
- def _squashed_graphs_triples (g1 , g2 ):
621
+ def _squashed_graphs_triples (g1 : Graph , g2 : Graph ):
619
622
for (t1 , t2 ) in zip (sorted (_squash_graph (g1 )), sorted (_squash_graph (g2 ))):
620
623
yield t1 , t2
621
624
622
625
623
- def _squash_graph (graph ):
626
+ def _squash_graph (graph : Graph ):
624
627
return (_squash_bnodes (triple ) for triple in graph )
625
628
626
629
0 commit comments