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

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

Closed
guacs opened this issue Oct 14, 2023 · 1 comment · Fixed by #569
Closed

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

guacs opened this issue Oct 14, 2023 · 1 comment · Fixed by #569

Comments

@guacs
Copy link

guacs commented Oct 14, 2023

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.

@jcrist
Copy link
Owner

jcrist commented Oct 17, 2023

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants