[issue44674] dataclasses should allow frozendict default value
Gianni Mariani
report at bugs.python.org
Sat Jul 24 02:45:59 EDT 2021
Gianni Mariani <gianni at mariani.ws> added the comment:
@Arjun - this is about default values (See the bug description - Using a frozendict as a default value)
Try this:
from frozendict import frozendict
from dataclasses import dataclass
@dataclass
class A:
a: frozendict = frozendict(a=1)
This used to work until frozendict became a subclass of dict.
Perhaps another fix is to convert any dict to a frozendict? Maybe not.
How would you handle this case? The only thing I figured was:
from frozendict import frozendict, field
from dataclasses import dataclass
AD=frozendict(a=1)
@dataclass
class A:
a: frozendict = field(default_factory=lambda:AD)
Which imho is cumbersome.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44674>
_______________________________________
More information about the Python-bugs-list
mailing list