Skip to content

Commit 0d8a7a8

Browse files
committed
Allow sorting of IDs by their value
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0430ea1 commit 0d8a7a8

File tree

1 file changed

+21
-0
lines changed
  • src/frequenz/client/microgrid

1 file changed

+21
-0
lines changed

src/frequenz/client/microgrid/_id.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ def __eq__(self, other: object) -> bool:
3131
# pylint: disable-next=unidiomatic-typecheck
3232
return type(other) is EnterpriseId and self._id == other._id
3333

34+
def __lt__(self, other: object) -> bool:
35+
"""Check if this instance is less than another object."""
36+
# pylint: disable-next=unidiomatic-typecheck
37+
if type(other) is EnterpriseId:
38+
return self._id < other._id
39+
return NotImplemented
40+
3441
def __hash__(self) -> int:
3542
"""Return the hash of this instance."""
3643
# We include the class because we explicitly want to avoid the same ID to give
@@ -73,6 +80,13 @@ def __eq__(self, other: object) -> bool:
7380
# pylint: disable-next=unidiomatic-typecheck
7481
return type(other) is MicrogridId and self._id == other._id
7582

83+
def __lt__(self, other: object) -> bool:
84+
"""Check if this instance is less than another object."""
85+
# pylint: disable-next=unidiomatic-typecheck
86+
if type(other) is MicrogridId:
87+
return self._id < other._id
88+
return NotImplemented
89+
7690
def __hash__(self) -> int:
7791
"""Return the hash of this instance."""
7892
# We include the class because we explicitly want to avoid the same ID to give
@@ -115,6 +129,13 @@ def __eq__(self, other: object) -> bool:
115129
# pylint: disable-next=unidiomatic-typecheck
116130
return type(other) is ComponentId and self._id == other._id
117131

132+
def __lt__(self, other: object) -> bool:
133+
"""Check if this instance is less than another object."""
134+
# pylint: disable-next=unidiomatic-typecheck
135+
if type(other) is ComponentId:
136+
return self._id < other._id
137+
return NotImplemented
138+
118139
def __hash__(self) -> int:
119140
"""Return the hash of this instance."""
120141
# We include the class because we explicitly want to avoid the same ID to give

0 commit comments

Comments
 (0)