Skip to content

Bug: dataclass with frozen and slots fails if defaults not provided #567

Closed

Description

@vkcku

Description

The following will fail:

from dataclasses import dataclass
import msgspec


@dataclass(frozen=True, slots=True)
class Foo:
    foo_value: int = 0


foo = msgspec.convert({}, Foo) # fails

The traceback:

Traceback (most recent call last):
  File "~/foo.py", line 9, in <module>
    foo = msgspec.convert({}, Foo)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 4, in __setattr__
dataclasses.FrozenInstanceError: cannot assign to field 'foo_value'

If the value for foo_value is provided in the initial dictionary, there is no error. Also, the error is only raised if slots=True is present.

Activity

  1. jcrist commented on Oct 17, 2023

    @jcrist
    Member

    Thanks for the excellent reproducible issue, this has been resolved in #569. I'll try to make a release in the next week or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions