[issue45520] Frozen dataclass deep copy doesn't work with __slots__

Christina Gorbenko report at bugs.python.org
Mon Oct 18 19:18:22 EDT 2021


New submission from Christina Gorbenko <jfuruness at gmail.com>:

If you define a frozen dataclass with slots and deep copy it, an error will occur. If you run the same code and remove the slots, the error will not occur. I assume this behavior is not intentional? Apologies if I'm submitting this wrong, this is the first time I've submitted an issue here so I'm not quite sure how to do it properly.

Example below:

```
from dataclasses import dataclass
from copy import deepcopy

@dataclass(frozen=True)
class FrozenData:
    # Without slots no errors occur?
    __slots__ = "my_string",

    my_string: str

deepcopy(FrozenData(my_string="initial"))
```

Error that occurs:
```
dataclasses.FrozenInstanceError: cannot assign to field 'my_string'
```

----------
messages: 404245
nosy: jfuruness
priority: normal
severity: normal
status: open
title: Frozen dataclass deep copy doesn't work with __slots__
type: behavior
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45520>
_______________________________________


More information about the Python-bugs-list mailing list