classification
Title: dataclasses should allow frozendict default value
Type: compile error Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, gianni
Priority: normal Keywords:

Created on 2021-07-19 14:06 by gianni, last changed 2021-07-19 14:18 by eric.smith.

Messages (2)
msg397799 - (view) Author: Gianni Mariani (gianni) Date: 2021-07-19 14:06
Using a frozendict as a default value should not cause an error in dataclasses. The check for mutability is:

   isinstance(f.default, (list, dict, set))

It appears frozendict has been changed to have a dict base class and it now raises an exception.

There should be a way to indicate object mutability as the purpose of the isinstance(f.default, (list, dict, set)) check is for mutable default values.

Using default_factory to work around this issue is cumbersome.
msg397800 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-07-19 14:18
I agree that would be an improvement.
History
Date User Action Args
2021-07-19 14:18:38eric.smithsetnosy: + eric.smith
messages: + msg397800
2021-07-19 14:06:32giannicreate