title: How to deal with "incompatible type "Optional[str]"; expected "str""?
body: <p>Let's say I have a code structure like this</p>
  <pre><code>from __future__ import annotations
  from typing import TypedDict
  
  
  class ValDict(TypedDict):
      something: str
      a: A
  
  
  class A:
      def __init__(self, x: str) -&gt; None:
          if x and isinstance(x, str):
              self.x = x
          else:
              raise ValueError(&quot;x has to be a non-empty string&quot;)
  
  
  class B:
      def __init__(self, something: str, a: A) -&gt; None:
          self.something = something
          if isinstance(a, A):
              self.a = a
          else:
              raise ValueError(&quot;a has to be of type A&quot;)
  
      @classmethod
      def from_dict(cls, stuff: ValDict) -&gt; B:
          something = stuff.get('something')
          a = stuff.get('a')
  
          return cls(something, a)
  </code></pre>
  <p>and I run <code>mypy</code> on this, I will receive 2 errors</p>
  <blockquote>
  <p>error: Argument 1 to &quot;B&quot; has incompatible type &quot;Optional[str]&quot;; expected &quot;str&quot;</p>
  </blockquote>
  <blockquote>
  <p>error: Argument 2 to &quot;B&quot; has incompatible type &quot;Optional[A]&quot;; expected &quot;A&quot;</p>
  </blockquote>
  <p>The errors are quite clear: As <code>.get</code> can also return <code>None</code>, I might not pass the correct types to the <code>cls</code> call in my <code>from_dict</code> method.</p>
  <p>My question is how to avoid it. For the argument <code>something</code> I could potentially get away with modifying to</p>
  <pre><code>something = stuff.get('something', '')
  </code></pre>
  <p>but how would I handle the case for <code>a</code>? Any ideas?</p>