title: mypy doesn't recognize Dictionary of Dictionary
body: <p>I'm trying to check my type annotations using mypy, but this error keeps ocurring:</p>
  <pre><code>Script.py:201: error: Item &quot;Dict[str, Union[float, int]]&quot; of &quot;Union[Dict[str, Union[float, int]], str, float, int, bool]&quot; has no 
  attribute &quot;endswith&quot;
  </code></pre>
  <p>My code looks like this:</p>
  <pre><code>from typing import Counter, Dict, Iterable, List, NoReturn, Optional, Set, Tuple, Union
  
  TYPE_NUMBER         = Union[float, int]
  TYPE_CONFIGURATION  = Dict[str, Union[Dict[str, TYPE_NUMBER], str, float, int, bool]]
  
  def check_configuration(config: TYPE_CONFIGURATION) -&gt; Union[bool, NoReturn]:
      database = 'database'
      assert isinstance(config[database], str)
      assert config[database].endswith('.prdb')
  </code></pre>
  <p>It runs just fine calling python normally. So I know the result of <code>config[database1]</code> is in fact a <strong>string</strong>. Is the problem is my type alias:</p>
  <p><code>TYPE_CONFIGURATION  = Dict[str, Union[Dict[str, TYPE_NUMBER], str, float, int, bool]]</code></p>
  <p>or is it a bug ?</p>
  <p>The <strong>config</strong> is a dict loaded from a JSON file where the only <strong>optional</strong> parameter is <em>&quot;start&quot;</em>. The JSON file looks like this:</p>
  <pre><code>{
      &quot;database&quot; : &quot;bla/bla/bla/file.csv&quot;,
      &quot;distance&quot; : 800,
      &quot;t&quot;        : false,
      &quot;output&quot;   : &quot;bla/bla/bla/file-out.csv&quot;,
  
      &quot;start&quot;    : {&quot;1&quot;: 1343.786, &quot;2&quot;: 1356.523}
  }
  </code></pre>