Skip to content

gh-125756: Document Pickler.clear_memo#125762

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
tomasr8:pickle-clear-memo
Feb 17, 2025
Merged

gh-125756: Document Pickler.clear_memo#125762
serhiy-storchaka merged 3 commits into
python:mainfrom
tomasr8:pickle-clear-memo

Conversation

@tomasr8

@tomasr8 tomasr8 commented Oct 20, 2024

Copy link
Copy Markdown
Member

Documents the public clear_memo which is currently undocumented. I think it makes to have it in the docs given that it is need when reusing Pickler objects.

The documentation is a copy of the docstring, but perhaps we could make it even clearer by replacing This method is useful when re-using picklers. with something like When reusing picklers, this method should be called after every call to dump?


📚 Documentation preview 📚: https://cpython-previews--125762.org.readthedocs.build/

Comment thread Doc/library/pickle.rst Outdated
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@erik895

erik895 commented Oct 23, 2024

Copy link
Copy Markdown

I hope you fix the problems with clear_memo before making this doc public
Did you read my comment about it on the original isue?

@FFY00

FFY00 commented Oct 23, 2024

Copy link
Copy Markdown
Member

I hope you fix the problems with clear_memo before making this doc public Did you read my comment about it on the original isue?

The function is public already unfortunately, the documentation is not the source of truth, the code is.

@FFY00

FFY00 commented Oct 23, 2024

Copy link
Copy Markdown
Member

The documentation is a copy of the docstring, but perhaps we could make it even clearer by replacing This method is useful when re-using picklers. with something like When reusing picklers, this method should be called after every call to dump?

That sounds good.

We should also warn the users about potential misuse, as pointed out by @erik895

@tomasr8

tomasr8 commented Oct 25, 2024

Copy link
Copy Markdown
Member Author

I hope you fix the problems with clear_memo before making this doc public Did you read my comment about it on the original isue?

Sorry for the late reply, had a busy week :/ As Filipe pointed out, the function is public so there is not much we can do besides documenting its gotchas.

I saw your example, though I think it's a pretty rare case to pickle multiple objects separately rather than just pickling one structure (list, dictionary, what have you..) and of course if you use clear_memo you can break things but there's no way to prevent someone from doing that if they really want to..

How about we add this note to the docs?

This method is useful when re-using picklers, however it should be avoided when
calling dump() repeatedly with the same file as it can cause unpickle() to load incorrect objects.

@serhiy-storchaka serhiy-storchaka merged commit 2542256 into python:main Feb 17, 2025
@serhiy-storchaka serhiy-storchaka added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Feb 17, 2025
@miss-islington-app

Copy link
Copy Markdown

Thanks @tomasr8 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @tomasr8 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 17, 2025
(cherry picked from commit 2542256)

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
@bedevere-app

bedevere-app Bot commented Feb 17, 2025

Copy link
Copy Markdown

GH-130231 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Feb 17, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 17, 2025
(cherry picked from commit 2542256)

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
@bedevere-app

bedevere-app Bot commented Feb 17, 2025

Copy link
Copy Markdown

GH-130232 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Feb 17, 2025
@serhiy-storchaka

Copy link
Copy Markdown
Member

Well, I am not sure about backporting the documentation. Usually this is not an issue, but one of options is to deprecate this function -- in that case it is not to document it in older versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants