title: How do I check if a value matches a type in python?
body: <p>Let's say I have a python function whose single argument is a non-trivial type:</p>
  
  <pre><code>from typing import List, Dict
  ArgType = List[Dict[str, int]]  # this could be any non-trivial type
  def myfun(a: ArgType) -&gt; None:
      ...
  </code></pre>
  
  <p>... and then I have a data structure that I have unpacked from a JSON source:</p>
  
  <pre><code>import json
  data = json.loads(...)
  </code></pre>
  
  <p>My question is: How can I check <em>at runtime</em> that <code>data</code> has the correct type to be used as an argument to <code>myfun()</code> before using it as an argument for <code>myfun()</code>?</p>
  
  <pre><code>if not isCorrectType(data, ArgType):
      raise TypeError("data is not correct type")
  else:
      myfun(data)
  </code></pre>