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

Avoid storing empty singleton on class itself in python implementation #86

Merged
merged 2 commits into from
Nov 15, 2023

Conversation

apmorton
Copy link
Contributor

@apmorton apmorton commented Nov 15, 2023

import dill
import frozendict


def test_foo():
    # this will work
    dill.dumps(frozendict.frozendict(a=1))

    # construct the first empty frozendict
    frozendict.frozendict()

    # this will blow up with:
    # dill._dill.PicklingWarning: Cannot locate reference to <class 'frozendict.core.frozendict'>.
    dill.dumps(frozendict.frozendict(a=1))

There are a few things going on here, but this solves the immediate problem that anyone anywhere constructing an empty frozendict when using the python implementation will change the behavior for subsequent calls to dill.dumps.

The larger issue, that I don't really know how to solve satisfactorily, is that dill thinks it needs to pickle the class itself rather than a reference to it. I will open an issue with more details about that.

See: #87 #88

src/frozendict/core.py Outdated Show resolved Hide resolved
src/frozendict/core.py Outdated Show resolved Hide resolved
src/frozendict/core.py Outdated Show resolved Hide resolved
@Marco-Sulla Marco-Sulla merged commit 1cf399f into Marco-Sulla:master Nov 15, 2023
7 checks passed
@apmorton apmorton deleted the am/avoid-empty-on-cls branch November 15, 2023 21:09
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.

None yet

2 participants