Repro:
» ./python.exe
Python 3.12.0a1+ (heads/cover-pysequence-slice-dirty:04cb2ecd5d, Nov 5 2022, 16:01:29) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle, statistics
>>> n = statistics.NormalDist(37.5, 5.625)
>>> pickle.dumps(n, protocol=0) # or `1`
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/Desktop/cpython/Lib/copyreg.py", line 94, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled
This is actually tested in test_statistics like this:
|
nd3 = pickle.loads(pickle.dumps(nd)) |
|
self.assertEqual(nd, nd3) |
But, it is only testing default protocol and is missing for proto in range(pickle.HIGHEST_PROTOCOL + 1): part. Note: this is the only place in all of the CPython tests, where protocol= is not passed. All other places do have the full check.
It looks like a bug to me and I will send a PR with the fix.
CC @rhettinger
Repro:
This is actually tested in
test_statisticslike this:cpython/Lib/test/test_statistics.py
Lines 3012 to 3013 in 8feb7ab
But, it is only testing default protocol and is missing
for proto in range(pickle.HIGHEST_PROTOCOL + 1):part. Note: this is the only place in all of the CPython tests, whereprotocol=is not passed. All other places do have the full check.It looks like a bug to me and I will send a PR with the fix.
CC @rhettinger
NormalDistpickle with0and1protocols #99156NormalDistpickle with0and1protocols (GH-99156). #99188NormalDistpickle with0and1protocols (GH-99156). (GH-99188) #99190