title: isinstance(foo,bar) vs type(foo) is bar
body: <p>A question of semantics, really.</p>
  
  <p>Up until recently, if I had to do any typechecking on a structure, I would use <code>type(obj) is list</code> et. al. However since joining SO I've noticed everyone (and I mean <em>EVERYONE</em>) uses <code>isinstance(obj,list)</code> instead. It seems they are synonymous, and <code>timeit</code> reveals almost IDENTICAL speed between them.</p>
  
  <pre><code>def a(): return type(list()) is list
  def b(): return isinstance(list(),list)
  
  from timeit import timeit
  timeit(a)
  # 0.5239454597495582
  timeit(b)
  # 0.5021292075273176
  </code></pre>
  
  <p>Indeed even <code>dis</code> agrees they're synonymous, with the exception of <code>type is</code>'s <code>COMPARE_OP</code></p>
  
  <pre><code>from dis import dis
  
  dis(a)
  # 2           0 LOAD_GLOBAL              0 (type) 
  #             3 LOAD_GLOBAL              1 (list) 
  #             6 CALL_FUNCTION            0 (0 positional, 0 keyword pair) 
  #             9 CALL_FUNCTION            1 (1 positional, 0 keyword pair) 
  #            12 LOAD_GLOBAL              1 (list) 
  #            15 COMPARE_OP               8 (is) 
  #            18 RETURN_VALUE
  
  dis(b)
  # 2           0 LOAD_GLOBAL              0 (isinstance)
  #             3 LOAD_GLOBAL              1 (list) 
  #             6 CALL_FUNCTION            0 (0 positional, 0 keyword pair) 
  #             9 LOAD_GLOBAL              1 (list) 
  #            12 CALL_FUNCTION            2 (2 positional, 0 keyword pair) 
  #            15 RETURN_VALUE 
  </code></pre>
  
  <p>I frankly find it more readable to say <code>if type(foo) is list:</code> than <code>if isinstance(foo,list):</code>, the first is basically just pseudo-code and the second calls some function (which I have to look up every time to be <code>isinstance</code> or <code>instanceof</code>) with some arguments. It doesn't look like a type cast, and there's no explicit way of knowing whether <code>isinstance(a,b)</code> is checking if <code>b</code> is an instance of <code>a</code> or vice-versa.</p>
  
  <p>I understand from <a href="https://stackoverflow.com/questions/1549801/differences-between-isinstance-and-type-in-python">this question</a> that we use <code>isinstance</code> because it's nicer about inheritance. <code>type(ClassDerivedFromList) is list</code> will fail while <code>isinstance(ClassDerivedFromList,list)</code> will succeed. But if I'm checking what should ALWAYS BE A BASE OBJECT, what do I really lose from doing <code>type is</code>?</p>