title: Mypy falsely reports error on union-typed variable when branching on type
body: <p>I ran into an issue when using mypy and have been able to find any help/reports regarding it. The following simplified code and error message should be self-explanatory:</p>
  
  <pre><code>#!/usr/bin/env python3
  
  from typing import List, Union
  
  class Corpus:
    path: List[str]
  
    def __init__(self, path:Union[str,List[str]]) -&gt; None:
      if type(path) == str:
        self.path = [path]
      else:
        self.path = path
  </code></pre>
  
  <p>Mypy gives the following errors:</p>
  
  <pre><code>simplified.py:10: error: List item 0 has incompatible type "Union[str, List[str]]"; expected "str"
  simplified.py:12: error: Incompatible types in assignment (expression has type "Union[str, List[str]]", variable has type "List[str]")
  </code></pre>
  
  <p>Even though the type of path variable is checked so that self.path should always result in string list, mypy complains about incompatible types.</p>
  
  <p>Am I overlooking something or is this a bug in mypy?
  (It it is a bug, should I go with <code>#type: ignore</code> annotation or is there a better work-around?)</p>
  
  <p>(Some background: I decided to ease my life by writing a module which would take care of some repeating work. The argument in question should be a path to text data and I expect it to be only one string most of the time so I don't want to force putting it in a list. However, I wish to allow specifying more paths too. Internally, I store it as a list anyway as iterator over the class is always initialized with such list (and then possibly extends it further by "unpacking" directories)).</p>