title: Cast an object to a derived type in Python
body: <p>I want to cast an object of type A to type B so I can use B's methods. Type B inherits A. For example I have class my class B:</p>
  
  <pre><code>class B(A):
      def hello(self):
          print('Hello, I am an object of type B')
  </code></pre>
  
  <p>My Library, Foo, has a function that returns an object of type A, which I want to cast to type B.</p>
  
  <pre><code>&gt;&gt;&gt;import Foo
  &gt;&gt;&gt;a_thing = Foo.getAThing()
  &gt;&gt;&gt;type(a_thing)
  A
  &gt;&gt;&gt;# Somehow cast a_thing to type B
  &gt;&gt;&gt;a_thing.hello()
  Hello, I am an object of type B
  </code></pre>