Skip to content

Commit 79fbcc5

Browse files
rhettingermiss-islington
authored andcommitted
bpo-36018: Make __pos__ return a distinct instance of NormDist (GH-12009)
https://bugs.python.org/issue36018
1 parent e895de3 commit 79fbcc5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Lib/statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ def __truediv__(x1, x2):
762762
return NormalDist(x1.mu / x2, x1.sigma / fabs(x2))
763763

764764
def __pos__(x1):
765-
return x1
765+
return NormalDist(x1.mu, x1.sigma)
766766

767767
def __neg__(x1):
768768
return NormalDist(-x1.mu, x1.sigma)

Lib/test/test_statistics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,18 @@ def test_cdf(self):
21282128
with self.assertRaises(statistics.StatisticsError):
21292129
Y.cdf(90)
21302130

2131+
def test_unary_operations(self):
2132+
NormalDist = statistics.NormalDist
2133+
X = NormalDist(100, 12)
2134+
Y = +X
2135+
self.assertIsNot(X, Y)
2136+
self.assertEqual(X.mu, Y.mu)
2137+
self.assertEqual(X.sigma, Y.sigma)
2138+
Y = -X
2139+
self.assertIsNot(X, Y)
2140+
self.assertEqual(X.mu, -Y.mu)
2141+
self.assertEqual(X.sigma, Y.sigma)
2142+
21312143
def test_same_type_addition_and_subtraction(self):
21322144
NormalDist = statistics.NormalDist
21332145
X = NormalDist(100, 12)

0 commit comments

Comments
 (0)