Skip to content

Commit ec98b3c

Browse files
committed
Implement __hash__
1 parent 045230d commit ec98b3c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

curtsies/formatstring.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ def __eq__(self, other):
157157
if not isinstance(other, Chunk):
158158
return False
159159
return self.s == other.s and self.atts == other.atts
160-
# TODO: corresponding hash method
160+
161+
def __hash__(self):
162+
# type: () -> int
163+
return hash(self.s, self.atts)
161164

162165
if PY3:
163166
__str__ = __unicode__
@@ -524,7 +527,10 @@ def __eq__(self, other):
524527
if isinstance(other, (unicode, bytes, FmtStr)):
525528
return str(self) == str(other)
526529
return False
527-
# TODO corresponding hash method
530+
531+
def __hash__(self):
532+
# type: () -> int
533+
return hash(str(self))
528534

529535
def __add__(self, other):
530536
# type: (Union[FmtStr, Text]) -> FmtStr

0 commit comments

Comments
 (0)