]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36018: Make __pos__ return a distinct instance of NormDist (GH-12009)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Sun, 24 Feb 2019 06:19:01 +0000 (22:19 -0800)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 24 Feb 2019 06:19:01 +0000 (22:19 -0800)
https://bugs.python.org/issue36018

Lib/statistics.py
Lib/test/test_statistics.py

index a73001ac554c881e5c6afd0d1ee9ef9193d00799..bf10e19c0d4138d997d13d3d86eec34233f6a7a1 100644 (file)
@@ -762,7 +762,7 @@ class NormalDist:
         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)
index a65fbe8dd259f0862749e752b9d45da08ff32955..9549240f9092462f7d475f9c46b4ddb996b00baf 100644 (file)
@@ -2128,6 +2128,18 @@ class TestNormalDist(unittest.TestCase):
         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)