title: Why is my Python dataclass not initialising boolean correctly?
body: <p>I'm currently writing some codes for an option pricer and at the same time I've been trying to experiment with Python dataclasses. Here I've two classes, <code>Option()</code> and <code>Option2()</code>, with the former written in dataclass syntax and latter in conventional class syntax.</p>
  <pre><code>from dataclasses import dataclass, field
  from typing import Optional
  
  @dataclass
  class Option:
      is_american: Optional[bool] = field(default=False)
      is_european: Optional[bool] = not is_american
  
  class Option2:
      def __init__(is_american=False):
          self.is_european = not is_american
  
  if __name__ == &quot;__main__&quot;:
      eu_option1 = Option()
      print(f&quot;{eu_option1.is_european = }&quot;)
      
      eu_option2 = Option2()
      print(f&quot;{eu_option2.is_european = }&quot;)
  </code></pre>
  <p>The output gives</p>
  <pre><code>eu_option1.is_european = False
  eu_option2.is_european = True
  </code></pre>
  <p>However, something very strange happened. Notice how in the <code>Option2()</code> case, <code>is_american</code> is set to <code>False</code> by default, and hence <code>is_european</code> must be <code>True</code> and it indeed is, so this is expected behaviour.</p>
  <p>But in the <code>dataclass</code> <code>Option()</code> case, <code>is_american</code> is also set to <code>False</code> by default. However, for whatever reason, the dataclass did not trigger the <code>is_european: Optional[bool] = not is_american</code> and hence <code>is_european</code> is still <code>False</code> when it is supposed to be <code>True</code>.</p>
  <p>What is going on here? Did I use my dataclass incorrectly?</p>