This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author stachel
Recipients stachel
Date 2018-03-17.23:03:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1521327830.3.0.467229070634.issue33094@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-03-17 23:03:50stachelsetrecipients: + stachel
2018-03-17 23:03:50stachelsetmessageid: <1521327830.3.0.467229070634.issue33094@psf.upfronthosting.co.za>
2018-03-17 23:03:50stachellinkissue33094 messages
2018-03-17 23:03:50stachelcreate