title: Convert an object to a new class
body: <p>I have two very similar classes. ExampleWithASurprise inherits from Example, having one more attribute. my_examples stores all the examples between their creation and the moment I convert them to a dict.</p>
  <pre><code>my_examples = []
  
  
  class Example:
      def __init__(self, stuff, morestuff):
          my_examples.append(self)
          self.stuff = stuff
          self.stiff = 10 + morestuff
  
      def to_dict(self):
          return {&quot;stuff&quot;: self.stuff, &quot;stiff&quot;: self.stiff}
  
  
  class ExampleWithASurprise(Example):
      def __init__(self, surprise, *args):
          Example.__init__(self, *args)
          self.surprise = surprise
  
      def to_dict(self):
          res = Example.to_dict(self)
          res[&quot;surprise&quot;] = self.surprise
          return res
  
  _ = Example(&quot;egg&quot;, 10)
  _ = ExampleWithASurprise(&quot;surprising surprise&quot;, &quot;bacon&quot;, 5)
  for e in my_examples:
      print(e.to_dict)
  </code></pre>
  <p>The problem is that I want a way to turn an ExampleWithASurprise into a regular Example (once the surprise has been discovered). I could add one method to ExampleWithASuprise:</p>
  <pre><code>class ExampleWithASurprise(Example):
      def __init__(self, surprise, *args):
          Example.__init__(self, *args)
          self.surprise = surprise
  
      def to_dict(self):
          res = Example.to_dict(self)
          res[&quot;surprise&quot;] = self.surprise
          return res
  
      def remove_surprise(self):
          my_examples.remove(self)
          _ = Example(self.stuff, self.stiff-10)
  
  
  ex1 = Example(&quot;egg&quot;, 10)
  ex2 = ExampleWithASurprise(&quot;surprising surprise&quot;, &quot;bacon&quot;, 5)
  ex2.remove_surprise()
  for e in my_examples:
      print(e.to_dict())
  </code></pre>
  <p>The surprise is conveniently removed, which is exactly what I wanted. However this remove_surprise method will quickly become impossible to maintain: in this example the only operation I do is adding 10, which is easily reversed, but the real classes I am interested in have more complex operations than that on their parameters.</p>
  <p>What would be the correct way to convert an ExampleWithASurprise into a plain Example so that to_dict works correctly and doesn't list the surprise?</p>