Message314072
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. |
|
Date |
User |
Action |
Args |
2018-03-19 01:15:57 | eric.smith | set | recipients:
+ eric.smith, stachel |
2018-03-19 01:15:56 | eric.smith | set | messageid: <1521422156.96.0.467229070634.issue33094@psf.upfronthosting.co.za> |
2018-03-19 01:15:56 | eric.smith | link | issue33094 messages |
2018-03-19 01:15:56 | eric.smith | create | |
|