title: How can I redefine the type() of instances of my Python class?
body: <p>I'm doing some debugging and need to ensure instances of my class have a specific type, e.g. <code>&lt;type 'list'&gt;</code>, when <code>type()</code> is called.</p>
  
  <p>The other option is redefining <code>type()</code> so it returns a different value when instances of my class are passed to it.</p>
  
  <p>For example:</p>
  
  <pre><code>class Test:
      def __str__(self):
          return 'anything'
  </code></pre>
  
  <p>allows me to set my own value when the instance is treated as a string e.g. <code>str(Test())</code>. I want something similar for <code>type(Test())</code>:</p>
  
  <pre><code>class Test:
      def __type__(self):
          return type([])
  </code></pre>
  
  <p>(not valid)</p>