title: Subclassing datatypes that have views in Python2.7 and Python3
body: <p>Python 3 introduced views (see <a href="https://stackoverflow.com/a/8960727/1326104">this question</a>). They were also backported to Python 2.7. I am currently in the process of subclassing <code>dict</code> in a Python 2.7 application (though with the goal to port it to Python 3 as well). I was wondering if - and how - I could subclass the <code>.viewitems()</code> and similar functions in such a way that they behave exactly like the original views.</p>
  
  <p>Here is my intent: I have a dictonary like this:</p>
  
  <pre><code>data = my_subclassed_dict
  data["_internal"] = "internal_value"
  data["key"] = "value"
  list(data.keys()) == ["key"]
  </code></pre>
  
  <p>That is, I filter everything stat starts with a <code>"_"</code>. This works fine so far: For iterators I just <code>yield</code> and for lists I use a list comprehension that filters undesired values. However, those items have no connection the <code>dict</code> anymore (which is fine, it feels exactly like a dict). However, with both ways, this does not work:</p>
  
  <pre><code>keys = data.viewkeys()
  "key" in keys
  del data["key"]
  "key" not in keys # This is False !
  </code></pre>
  
  <p>The last part does not work because there is no reference to the original keys, so Python won't notice.</p>
  
  <p>So: Is there a <strong>simple</strong> way to achieve this (without re-implementing all of the logic!)?</p>
  
  <p>This is more of a question out of interest as I don't see it to apply that much in my scenario.</p>