Skip to content

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

Merged
Marco-Sulla merged 2 commits intoMarco-Sulla:masterfrom
apmorton:am/avoid-empty-on-cls
Nov 15, 2023
Merged

Avoid storing empty singleton on class itself in python implementation#86
Marco-Sulla merged 2 commits intoMarco-Sulla:masterfrom
apmorton:am/avoid-empty-on-cls

Conversation

@apmorton
Copy link
Copy Markdown
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

@Marco-Sulla Marco-Sulla merged commit 1cf399f into Marco-Sulla:master Nov 15, 2023
@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.

2 participants