Skip to content

Commit fa6e1be

Browse files
committed
Add "Comparable" Protocol
From python/typing#59 (comment)
1 parent 03f0657 commit fa6e1be

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎whatshap/graph.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
"""
22
Find connected components.
33
"""
4+
from abc import abstractmethod
5+
from typing import TypeVar, Generic, Optional, Iterable, Protocol
46

7+
T = TypeVar("T")
8+
C = TypeVar("C", bound="Comparable")
59

6-
class Node:
7-
def __init__(self, value, parent):
10+
11+
class Comparable(Protocol):
12+
@abstractmethod
13+
def __lt__(self: C, other: C) -> bool:
14+
pass
15+
16+
17+
class Node(Generic[T]):
18+
def __init__(self, value: T, parent: Optional["Node"]):
819
self.value = value
920
self.parent = parent
1021

0 commit comments

Comments
 (0)