Skip to content

Commit 652a1cb

Browse files
bpo-38521: Fix error in NormalDist.__eq__() (GH-16840) (GH-16842)
(cherry picked from commit 5eabec0) Co-authored-by: Raymond Hettinger <[email protected]>
1 parent 5fb8142 commit 652a1cb

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ def __eq__(x1, x2):
10921092
"Two NormalDist objects are equal if their mu and sigma are both equal."
10931093
if not isinstance(x2, NormalDist):
10941094
return NotImplemented
1095-
return (x1._mu, x2._sigma) == (x2._mu, x2._sigma)
1095+
return x1._mu == x2._mu and x1._sigma == x2._sigma
10961096

10971097
def __hash__(self):
10981098
"NormalDist objects hash equal if their mu and sigma are both equal."

Lib/test/test_statistics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,9 +2651,13 @@ def test_equality(self):
26512651
nd2 = NormalDist(2, 4)
26522652
nd3 = NormalDist()
26532653
nd4 = NormalDist(2, 4)
2654+
nd5 = NormalDist(2, 8)
2655+
nd6 = NormalDist(8, 4)
26542656
self.assertNotEqual(nd1, nd2)
26552657
self.assertEqual(nd1, nd3)
26562658
self.assertEqual(nd2, nd4)
2659+
self.assertNotEqual(nd2, nd5)
2660+
self.assertNotEqual(nd2, nd6)
26572661

26582662
# Test NotImplemented when types are different
26592663
class A:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed erroneous equality comparison in statistics.NormalDist().

0 commit comments

Comments
 (0)