Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea2316a

Browse files
[3.10] [ GH-99155: Fix NormalDist pickle with 0 and 1 protocols (GH-99156). (GH-99188) (GH-99190)
1 parent 1b5a62b commit ea2316a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Lib/statistics.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,3 +1265,9 @@ def __hash__(self):
12651265

12661266
def __repr__(self):
12671267
return f'{type(self).__name__}(mu={self._mu!r}, sigma={self._sigma!r})'
1268+
1269+
def __getstate__(self):
1270+
return self._mu, self._sigma
1271+
1272+
def __setstate__(self, state):
1273+
self._mu, self._sigma = state

Lib/test/test_statistics.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,14 +2880,19 @@ def __init__(self, mu, sigma):
28802880
nd = NormalDist(100, 15)
28812881
self.assertNotEqual(nd, lnd)
28822882

2883-
def test_pickle_and_copy(self):
2883+
def test_copy(self):
28842884
nd = self.module.NormalDist(37.5, 5.625)
28852885
nd1 = copy.copy(nd)
28862886
self.assertEqual(nd, nd1)
28872887
nd2 = copy.deepcopy(nd)
28882888
self.assertEqual(nd, nd2)
2889-
nd3 = pickle.loads(pickle.dumps(nd))
2890-
self.assertEqual(nd, nd3)
2889+
2890+
def test_pickle(self):
2891+
nd = self.module.NormalDist(37.5, 5.625)
2892+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2893+
with self.subTest(proto=proto):
2894+
pickled = pickle.loads(pickle.dumps(nd, protocol=proto))
2895+
self.assertEqual(nd, pickled)
28912896

28922897
def test_hashability(self):
28932898
ND = self.module.NormalDist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :class:`statistics.NormalDist` pickle with ``0`` and ``1`` protocols.

0 commit comments

Comments
 (0)