-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
pickle docs are wrong about nested classes #91362
Comments
https://docs.python.org/3.10/library/pickle.html#what-can-be-pickled-and-unpickled says that only "classes that are defined at the top level of a module" can be pickled. But in fact these work fine in current Python, probably since 3.3 when __qualname__ was added (https://docs.python.org/3/library/stdtypes.html#definition.\_\_qualname__). Similarly, the docs claim only top-level functions can be pickled, but in fact methods nested in classes work fine. Example script demonstrating that these work: import pickle
class X:
class Y:
pass
def method(self):
pass
print(pickle.dumps(X.Y))
print(pickle.loads(pickle.dumps(X.Y)))
print(pickle.dumps(X.Y()))
print(pickle.loads(pickle.dumps(X.Y())))
print(pickle.dumps(X.method))
print(pickle.loads(pickle.dumps(X.method))) |
…honGH-92429) Fixes pythonGH-91362 (cherry picked from commit f9d6c59) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
…honGH-92429) Fixes pythonGH-91362 (cherry picked from commit f9d6c59) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: