Skip to content

statistics.NormalDist fails to be pickled with 0 and 1 protocols #99155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue Nov 6, 2022 · 2 comments
Closed

statistics.NormalDist fails to be pickled with 0 and 1 protocols #99155

sobolevn opened this issue Nov 6, 2022 · 2 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 6, 2022

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

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Nov 6, 2022
@sobolevn sobolevn self-assigned this Nov 6, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 6, 2022
@rhettinger rhettinger self-assigned this Nov 7, 2022
@rhettinger
Copy link
Contributor

I've applied this to main. Can you please prepare the backport PR?

vfazio pushed a commit to vfazio/cpython that referenced this issue Nov 7, 2022
vfazio pushed a commit to vfazio/cpython that referenced this issue Nov 7, 2022
@sobolevn
Copy link
Member Author

sobolevn commented Nov 7, 2022

Yes, sure!
Thank you.

sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 7, 2022
…cols (pythonGH-99156).

(cherry picked from commit d7a00f1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 7, 2022
…cols (pythonGH-99156).

(cherry picked from commit d7a00f1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit that referenced this issue Nov 7, 2022
…H-99156). (GH-99188)

(cherry picked from commit d7a00f1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Automerge-Triggered-By: GH:rhettinger
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 7, 2022
…cols (pythonGH-99156). (pythonGH-99188)

(cherry picked from commit d7a00f1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
(cherry picked from commit 263e983)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Automerge-Triggered-By: GH:rhettinger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants