title: Python mypy checking of return types for TypeVar(bound=Union[A, B]) doesn't error vs TypeVar(A, B) does error
body: <p>I am stuck trying to understand bounding of <code>TypeVar</code> when using it in two different ways:</p>
  
  <ul>
  <li><code>Enums = TypeVar("Enums", Enum1, Enum2)</code></li>
  <li><code>Enums = TypeVar("Enums", bound=Union[Enum1, Enum2])</code></li>
  </ul>
  
  <p>Here is the code I am using:</p>
  
  <pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python3.6
  
  """Figuring out why enum is saying incompatible return type."""
  
  
  from enum import IntEnum, EnumMeta
  from typing import TypeVar, Union
  
  
  class Enum1(IntEnum):
  
      MEMBER1 = 1
      MEMBER2 = 2
  
  
  class Enum2(IntEnum):
  
      MEMBER3 = 3
      MEMBER4 = 4
  
  
  # Enums = TypeVar("Enums", bound=Union[Enum1, Enum2])  # Case 1... Success
  Enums = TypeVar("Enums", Enum1, Enum2)  # Case 2... error: Incompatible return value
  
  
  def _enum_to_num(val: int, cast_enum: EnumMeta) -&gt; Enums:
      return cast_enum(val)
  
  
  def get_some_enum(val: int) -&gt; Enum1:
      return _enum_to_num(val, Enum1)
  
  
  def get_another_enum(val: int) -&gt; Enum2:
      return _enum_to_num(val, Enum2)  # line 35
  </code></pre>
  
  <p>When running <code>mypy==0.770</code>:</p>
  
  <ul>
  <li><code>Case 1</code>: <code>Success: no issues found</code></li>
  <li><code>Case 2</code>: <code>35: error: Incompatible return value type (got "Enum1", expected "Enum2")</code></li>
  </ul>
  
  <p>This case is <em>very</em> similar to this question: <a href="https://stackoverflow.com/questions/59933946/difference-between-typevart-a-b-and-typevart-bound-uniona-b">Difference between TypeVar(&#39;T&#39;, A, B) and TypeVar(&#39;T&#39;, bound=Union[A, B])</a></p>
  
  <p>The answer explains when using case 1(<code>bound=Union[Enum1, Enum2]</code>), the following is legal:</p>
  
  <ol>
  <li><code>Union[Enum1, Enum2]</code></li>
  <li><code>Enum1</code></li>
  <li><code>Enum2</code></li>
  </ol>
  
  <p>And when using case 2 (<code>A, B</code>), the following is legal:</p>
  
  <ol>
  <li><code>Enum1</code></li>
  <li><code>Enum2</code></li>
  </ol>
  
  <hr>
  
  <p>However, I don't think this answer explains my problem, I am not using the <code>Union</code> case.</p>
  
  <p>Can anyone please tell me what's going on?</p>