Adrian Stachlewski added the comment:
There's nothing to do, thanks for help one more again.
--
status: pending -> open
___
Python tracker
<https://bugs.python.org
Adrian Stachlewski added the comment:
There's also another major problem. Because Base.x has value, __init__ is not
prepared correctly (member_descriptor is passed as default).
@dataclass
class Base:
__slots__ = ('x',)
x: Any
Base() # No TypeError exception
Fixing
Adrian Stachlewski added the comment:
I don't really get your point.
@dataclass
class Base:
__slots__ = ('x',)
x: Any
This case is described in PEP 557 as correct, so I don't understand why you
want to generate error. Also inheritance without defining slots is c
Adrian Stachlewski added the comment:
Once more same mistake.
'x' should be declared as:
- x: ClassVar[set] = set()
- x: ClassVar[Set[Any]] = set()
--
___
Python tracker
<https://bugs.python.o
New submission from Adrian Stachlewski :
I've tried to declare two classes
@dataclass
class Base:
__slots__ = ('x',)
x: Any
@dataclass
class Derived(Base):
x: int
y: int
As long as I correctly understood PEP 557 (inheritance part), changing type of
variable is
Adrian Stachlewski added the comment:
Thanks for explaining. I was trying to do something like
@dataclass
class A:
x: ClassVar = set()
and thanks to you I know it should be
@dataclass
class A:
x: ClassVar[Set] = set()
If you are looking for improved error message, it's probably s
New submission from Adrian Stachlewski :
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()