Eric V. Smith <[email protected]> added the comment:
There are a couple of problems here. You're using ClassVar incorrectly. It
should be:
>>> @dataclass
... class C:
... __slots__=()
... x: ClassVar[int] = field(default=3)
...
>>> C()
C()
>>> C.x
3
And you cannot have a ClassVar with a default_factory, since it would never get
called:
>>> @dataclass
... class C:
... __slots__=()
... x: ClassVar[int] = field(default_factory=set)
...
raise TypeError(f'field {f.name} cannot have a '
TypeError: field x cannot have a default factory
Although this error message could be improved. Neither InitVars or ClassVars
can have default factories.
I'm not exactly sure how to improve the error message that you're seeing.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33094>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com