[Python-checkins] bpo-36018: Make __pos__ return a distinct instance of NormDist (GH-12009)

Miss Islington (bot) webhook-mailer at python.org
Sun Feb 24 01:19:09 EST 2019


https://github.com/python/cpython/commit/79fbcc597dfd039d3261fffcb519b5ec5a18df9d
commit: 79fbcc597dfd039d3261fffcb519b5ec5a18df9d
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2019-02-23T22:19:01-08:00
summary:

bpo-36018: Make __pos__ return a distinct instance of NormDist (GH-12009)



https://bugs.python.org/issue36018

files:
M Lib/statistics.py
M Lib/test/test_statistics.py

diff --git a/Lib/statistics.py b/Lib/statistics.py
index a73001ac554c..bf10e19c0d41 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -762,7 +762,7 @@ def __truediv__(x1, x2):
         return NormalDist(x1.mu / x2, x1.sigma / fabs(x2))
 
     def __pos__(x1):
-        return x1
+        return NormalDist(x1.mu, x1.sigma)
 
     def __neg__(x1):
         return NormalDist(-x1.mu, x1.sigma)
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index a65fbe8dd259..9549240f9092 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -2128,6 +2128,18 @@ def test_cdf(self):
         with self.assertRaises(statistics.StatisticsError):
             Y.cdf(90)
 
+    def test_unary_operations(self):
+        NormalDist = statistics.NormalDist
+        X = NormalDist(100, 12)
+        Y = +X
+        self.assertIsNot(X, Y)
+        self.assertEqual(X.mu, Y.mu)
+        self.assertEqual(X.sigma, Y.sigma)
+        Y = -X
+        self.assertIsNot(X, Y)
+        self.assertEqual(X.mu, -Y.mu)
+        self.assertEqual(X.sigma, Y.sigma)
+
     def test_same_type_addition_and_subtraction(self):
         NormalDist = statistics.NormalDist
         X = NormalDist(100, 12)



More information about the Python-checkins mailing list