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