title: Python dataclass inheritance with class variables
body: <p>Consider the following example code</p>
  <pre><code>from dataclasses import dataclass, field
  from typing import ClassVar
  
  
  @dataclass
  class Base:
      x: str = field(default='x', init=False)
  
  
  @dataclass
  class A(Base):
      name: str
  
  
  @dataclass
  class B(Base):
      name: str
  
  
  a = A('test_a')
  b = B('test_b')
  
  a.x = 'y'
  a.x  # prints 'y'
  b.x  # prints 'x'
  </code></pre>
  <p>which prints 'y' and 'x' as expected.</p>
  <p>Now I'd like to make <code>x</code> a ClassVar of type <code>dict</code>:</p>
  <pre><code>from dataclasses import dataclass, field
  from typing import ClassVar, Dict
  
  
  @dataclass
  class Base:
      x: ClassVar[Dict[str, str]] = field(default={'x': 'x'}, init=False)
  
  
  @dataclass
  class A(Base):
      name: str
  
  
  @dataclass
  class B(Base):
      name: str
  
  
  a = A('test_a')
  b = B('test_b')
  
  a.x['y'] = 'y'
  a.x
  b.x
  </code></pre>
  <p>However, now the output is</p>
  <pre><code>a.x =&gt; {'x': 'x', 'y': 'y'}
  b.x =&gt; {'x': 'x', 'y': 'y'}
  </code></pre>
  <p>I'd expect that only <code>a.x</code> gets modified and <code>b.x</code> stays at the default init value `{'x': 'x'}.</p>
  <p>If the field would not be a <code>ClassVar</code> then I could use the <code>default_factory=dict</code> but that doesn't work in combination with <code>ClassVar</code> since it returns the error</p>
  <pre><code> Field cannot have a default factory
  </code></pre>