[New-bugs-announce] [issue33094] dataclasses: ClassVar attributes are not working properly
Adrian Stachlewski
report at bugs.python.org
Sat Mar 17 19:03:50 EDT 2018
New submission from Adrian Stachlewski <adrian.stachlewski at gmail.com>:
Class variables should behave in the same way whether with or without ClassVar annotation. Unfortunately there are not.
class A:
__slots__ = ()
x: ClassVar = set()
A() # it's ok
@dataclass
class B:
__slots__ = ()
x = set()
B() # ok too
@dataclass
class C:
__slots__ = ()
# cannot use set() because of error
x: ClassVar = field(default_factory=set)
C() # AttributeError: 'C' object has no attribute 'x'
Exception is raised from __init__ method, with flag init=False nothing changes.
Python version: 3.7.0b2
----------
components: Library (Lib)
messages: 314017
nosy: stachel
priority: normal
severity: normal
status: open
title: dataclasses: ClassVar attributes are not working properly
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33094>
_______________________________________
More information about the New-bugs-announce
mailing list