title: Using python type hints as runtime type checking (raise TypeError if different)
body: <p>I have an example function:</p>
  
  <pre class="lang-py prettyprint-override"><code>from typing import Dict
  
  
  def cool_func(foo: Dict[object, str], bar: bool, baz: float) -&gt; None:
      foo_type_error_msg = "foo must be a Dict[object, str]"
      if not foo.isinstance(dict):
          raise TypeError(foo_type_error_msg)
      for s in foo.values():
          if not s.isinstance(str):
              raise TypeError(foo_type_error_msg)
  
      # the rest of the function
  </code></pre>
  
  <p>How can I use the type specified in the type hints to check the variable at runtime? Please note that I don't want to be strict on other variables (just check the <code>foo</code> parameter).</p>
  
  <p>In case you wonder, I want to enforce the type so that the error (caused by the wrong Type) won't appear somewhere in <code>the rest of the function</code> and confuse the user with the default error message.</p>
  
  <p>I wish that I can have something like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>def cool_func(foo: Dict[object, str], bar: bool, baz: float) -&gt; None:
      check_type('foo')
      # the rest of the function
  </code></pre>
  
  <p>or at least</p>
  
  <pre class="lang-py prettyprint-override"><code>def cool_func(foo: Dict[object, str], bar: bool, baz: float) -&gt; None:
      check_type(foo, 'Dict[object, str]')
      # the rest of the function
  </code></pre>