title: Wrapping an already existent class
body: <p>I've run into a bug where an iterator which loops through data is giving the shorter then expected remainder at the end of the set before looping back to the beginning. I need all iterations to be exactly the same size so I'd like it to drop the leftover part. Unfortunately The iterator is called as an argument for another object so I have no control over when <code>__next__()</code> is called. The solution that comes to mind is to make a custom class that inherits from the iterator and only redefine <code>__next__()</code>.</p>
  
  <p>I'm trying to do this as follows:</p>
  
  <pre class="lang-py prettyprint-override"><code>class CleanIterator(NumpyArrayIterator):
  
      def __init__(self, _super):
          super=_super
  
      def __next__(self, *args, **kwargs):
          return self.next(*args, **kwargs)
  
      def next(self, *args, **kwargs):
          while True:
              data= super.next(*args, **kwargs)
  
              # reject short data snippets
              if data[0].shape[0] == self.batch_size:
                  return data
  
  # .flow return a NumpyArrayIterator
  data_generator= ImageDataGenerator().flow(
          valid_data, valid_labels,
          batch_size= 100)
  data_generator= CleanIterator(data_generator)
  </code></pre>
  
  <p>This manages to inherit functions from multiple levels of inheritance, but only appears to inherit variables from NumpyArrayIterator.</p>
  
  <p>As a result I get errors like this:</p>
  
  <pre><code>venv/lib/python3.6/site-packages/keras_preprocessing/image/iterator.py", line 68, in __len__
      return (self.n + self.batch_size - 1) // self.batch_size  # round up
  AttributeError: 'CleanIterator' object has no attribute 'n'
  </code></pre>
  
  <p>where NumpyArrayIterator inherits from Iterator. Iterator has variable <code>self.n</code> and function <code>__len__()</code>.</p>
  
  <p>I've tried looking for the proper syntax but every example I can find builds the parent class from scratch rather than starting with an extant instance.</p>
  
  <p>So I guess the question is: how do you create an new instance of child-class from an old instance of parent-class?</p>