Skip to content
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

a close reading of the pickle module #12971

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

tungol
Copy link
Contributor

@tungol tungol commented Nov 7, 2024

I didn't go in planning to split the C _pickle.Picker and python pickle._Pickler implementations, but then the _Pickler-only classvar was there and I didn't like copying that into _pickle.pyi.

Pickler.memo and Unpickler.memo I went as far as I did with it because of the comment here: https://github.com/python/cpython/blob/3.12/Modules/_pickle.c#L4839

which pretty strongly implies that somebody out there is using it.

Copy link
Contributor

github-actions bot commented Nov 7, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@tungol tungol marked this pull request as draft November 7, 2024 06:32
@tungol tungol marked this pull request as ready for review November 7, 2024 07:00
Comment on lines +12 to +16
# This protocol approximates the undocumented PicklerMemoProxy
# and UnpicklerMemoProxy types.
class _MemoProxy(Protocol):
def clear(self, /) -> None: ...
def copy(self, /) -> dict[int, tuple[int, Any]]: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm of two minds here. I like the protocol for the getter return type; it avoids having the PicklerMemoProxy class in the stubs, where it could imply it's importable, and it isn't. I might feel better about that if it was named _PicklerMemoProxy, but alas.

I dislike the protocol for the setter value, because that method actually does do an identity check on PicklerMemoProxy or UnpicklerMemoProxy, depending.

I have been pondering this since I opened the MR, and have flipped back and forth which I think is better a couple times now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant