Skip to content

Commit dfbfbaa

Browse files
committed
Fix Version.__hash__ to be consistent with __eq__.
Two bugs: 1. __hash__ uses _unparsed (raw string) but __eq__ uses _parsed, so "1" == "1.0" but hash differs. 2. _normalize doesn't recurse into sublists, so _parsed isn't fully canonical: "1-2-0" gets (1,(2,())) instead of (1,(2,)). Fix _normalize to recurse into sublists first, making _parsed canonical, then use hash(_parsed) for __hash__. Fixes #189 Signed-off-by: Matt Selsky <matthew.selsky@twosigma.com>
1 parent 92b1a24 commit dfbfbaa

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/univers/maven.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def __eq__(self, other):
419419
return self.__cmp__(other) == 0
420420

421421
def __hash__(self):
422-
return hash(self._unparsed)
422+
return hash(self._parsed)
423423

424424
def __lt__(self, other):
425425
return self.__cmp__(other) < 0
@@ -492,6 +492,9 @@ def _new_list(self, l):
492492
return sublist
493493

494494
def _normalize(self, l):
495+
for i, item in enumerate(l):
496+
if isinstance(item, list):
497+
self._normalize(item)
495498
for item in l[::-1]:
496499
if not item:
497500
l.pop()

0 commit comments

Comments
 (0)