Skip to content

Different behaviour in class variable assignment from dataclasses when slots=True #12

Description

@Glinte
# FIXME: semimutable always handles class variables consistently regardless of slots=True, but seems like dataclasses does not.
@pytest.mark.xfail
def test_class_attribute_rebinding_is_not_noop_if_slots_true():
    @dataclasses.dataclass
    class Std:
        x: int = dataclasses.field()

    @semimutable.dataclass
    class Sm:
        x: int = semimutable.field(frozen=True)

    std = Std(x=5)
    sm = Sm(x=5)
    Std.x = 123
    Sm.x = 123
    assert std.x == sm.x == 123  # This is what dataclasses does, but semimutable does not. Instead, sm.x == 5 here.
    assert Std.x == Sm.x == 123

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions