summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-10-18 14:20:35 -0700
committerGitHub <noreply@github.com>2019-10-18 14:20:35 -0700
commit5eabec022b9a10734fcf58faad02c4d233592f64 (patch)
tree035bcaf1e28477e23804776247193ef1a4c94024
parentecb035cd14c11521276343397151929a94018a22 (diff)
downloadcpython-git-5eabec022b9a10734fcf58faad02c4d233592f64.tar.gz
bpo-38521: Fix error in NormalDist.__eq__() (GH-16840)
-rw-r--r--Lib/statistics.py2
-rw-r--r--Lib/test/test_statistics.py4
-rw-r--r--Misc/NEWS.d/next/Library/2019-10-18-13-57-31.bpo-38521.U-7aaM.rst1
3 files changed, 6 insertions, 1 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 0d747b3d6c..461ffae3f4 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -1092,7 +1092,7 @@ class NormalDist:
"Two NormalDist objects are equal if their mu and sigma are both equal."
if not isinstance(x2, NormalDist):
return NotImplemented
- return (x1._mu, x2._sigma) == (x2._mu, x2._sigma)
+ return x1._mu == x2._mu and x1._sigma == x2._sigma
def __hash__(self):
"NormalDist objects hash equal if their mu and sigma are both equal."
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index af26473e8f..bebd9b5d6f 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -2651,9 +2651,13 @@ class TestNormalDist:
nd2 = NormalDist(2, 4)
nd3 = NormalDist()
nd4 = NormalDist(2, 4)
+ nd5 = NormalDist(2, 8)
+ nd6 = NormalDist(8, 4)
self.assertNotEqual(nd1, nd2)
self.assertEqual(nd1, nd3)
self.assertEqual(nd2, nd4)
+ self.assertNotEqual(nd2, nd5)
+ self.assertNotEqual(nd2, nd6)
# Test NotImplemented when types are different
class A:
diff --git a/Misc/NEWS.d/next/Library/2019-10-18-13-57-31.bpo-38521.U-7aaM.rst b/Misc/NEWS.d/next/Library/2019-10-18-13-57-31.bpo-38521.U-7aaM.rst
new file mode 100644
index 0000000000..9335bdc954
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-10-18-13-57-31.bpo-38521.U-7aaM.rst
@@ -0,0 +1 @@
+Fixed erroneous equality comparison in statistics.NormalDist().