diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index 275ed338b..e031fe5c3 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -703,9 +703,9 @@ def test_issue856b(self): def test_issue876(self): # Same hash must not imply equality. - # As an implementation detail of CPython, hash(-1) == hash(-2) This test is - # useless in potential alternative Python implementations where hash(-1) != - # hash(-2); one would need to find hash collisions specific for each + # As an implementation detail of CPython, hash(-1) == hash(-2). + # This test is useless in potential alternative Python implementations where + # hash(-1) != hash(-2); one would need to find hash collisions specific for each # implementation a = UnitsContainer({"[mass]": -1}) diff --git a/pint/util.py b/pint/util.py index d8ebcace0..d89b9579a 100644 --- a/pint/util.py +++ b/pint/util.py @@ -327,11 +327,12 @@ def __setstate__(self, state): def __eq__(self, other): if isinstance(other, UnitsContainer): - out = UnitsContainer.__hash__(self) == UnitsContainer.__hash__(other) + # UnitsContainer.__hash__(self) is not the same as hash(self); see + # ParserHelper.__hash__ and __eq__. # Different hashes guarantee that the actual contents are different, but - # identical hashes give no guarantee of equality + # identical hashes give no guarantee of equality. # e.g. in CPython, hash(-1) == hash(-2) - if not out: + if UnitsContainer.__hash__(self) != UnitsContainer.__hash__(other): return False other = other._d