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

Dumping sets of dataclasses #348

Closed
bomzheg opened this issue Dec 3, 2024 · 2 comments
Closed

Dumping sets of dataclasses #348

bomzheg opened this issue Dec 3, 2024 · 2 comments
Labels

Comments

@bomzheg
Copy link

bomzheg commented Dec 3, 2024

Hello and thank you for amazing library!
i have problem with next simple example:

from dataclasses import dataclass

import pytest
from adaptix import Retort
from adaptix._internal.morphing.provider_template import ABCProxy

@dataclass(frozen=True)
class B:
    b: str

@dataclass
class A:
    a: set[B]

@pytest.fixture
def retort() -> Retort:
    return Retort(
        recipe=[
            ABCProxy(set, list, for_loader=False),
        ]
    )

def test_retort(retort: Retort):
    assert retort.dump(set(), set) == []
    assert retort.load([], set) == set()
    assert retort.dump({1, 2}, set) == [1, 2]
    assert retort.load([1, 2], set) == {1, 2}
    assert retort.dump(A({B("a")})) == {"a": [{"b": "a"}]}

This test failed with next error:

FAILED                                  [100%]
test_deserialize.py:106 (test_retort)
{'a': [B(b='a')]} != {'a': [{'b': 'a'}]}

Expected :{'a': [{'b': 'a'}]}
Actual   :{'a': [B(b='a')]}

retort = <adaptix._internal.morphing.facade.retort.Retort object at 0x7fc7ba919210>

    def test_retort(retort: Retort):
        assert retort.dump(set(), set) == []
        assert retort.load([], set) == set()
        assert retort.dump({1, 2}, set) == [1, 2]
        assert retort.load([1, 2], set) == {1, 2}
>       assert retort.dump(A({B("a")})) == {"a": [{"b": "a"}]}
E       AssertionError: assert {'a': [B(b='a')]} == {'a': [{'b': 'a'}]}
E         Differing items:
E         {'a': [B(b='a')]} != {'a': [{'b': 'a'}]}
E         Full diff:
E         - {'a': [{'b': 'a'}]}
E         + {'a': [B(b='a')]}

test_deserialize.py:112: AssertionError
@bomzheg
Copy link
Author

bomzheg commented Dec 3, 2024

I guess we newer want to save sets after loading, so we can convert any Iterable to lists and it will be great in most cases

@zhPavel zhPavel added type: bug Something isn't working domain: loading & dumping labels Dec 8, 2024
zhPavel added a commit that referenced this issue Dec 8, 2024
Fix #348, Iterable is now converted to tuple or list
@zhPavel
Copy link
Member

zhPavel commented Dec 8, 2024

Fixed at #349

@zhPavel zhPavel closed this as completed Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants