title: can any recursive looping happen from overwriting __dir__ in python
body: <p>Suppose, I have a custom class that does not inherit from another class (which is typically hard to inherit from), but builds a wrapper along with a few other functions that modify the behavior of the second class. </p>
  
  <pre><code>class TestClass:
     def __init__(self, *args, **kwargs):
         self.data = OrigClass(*args, **kwargs)
  
     def __getitem__(self, key):
         ...
         x = self.data.__getitem__(key)
         ...
  
     def __setitem__(self, key, value):
         ...
         self.data.__setitem__(key, value)
         ...
  
     @staticmethod
     def _try_attr(var, item):
         if hasattr(var, item):
             return var.__getattribute__(item)
         else:
             return None
  
  
     def __getattr__(self, item):
         return TestClass._try_attr(self._data, item)
  
  
     def __repr__(self):
         ...
  
     def __str__(self):
         ...
  </code></pre>
  
  <p>As such, the <code>TestClass</code> is working fine with the new modifications, and falling back on <code>OrigClass</code> for methods using <code>__getattr__</code> for methods that were not re-implemented. However, in interactive mode (e.g. PyCharm's Python console) or otherwise, when I try to see <code>__dir__()</code>, the <code>__dir__()</code> in <code>TestClass</code> doesn't display / show all the attributes in <code>OrigClass</code> that are also accessible in <code>TestClass</code>. </p>
  
  <p>I can try to create a new <code>__dir__</code> function within <code>TestClass</code> to merge the current <code>TestClass</code>'s <code>__dir__</code> with the <code>__dir__</code> in <code>OrigClass</code> to create <code>__dir__</code> (I'm using Python 3.x). There seems to some posts on this on SO (although not sure some of them are valid for Python 3.x). </p>
  
  <ol>
  <li><p>However, I am worried about the common functions in <code>OrigClass</code> and <code>TestClass</code>, i.e. if there are functions like <code>__setitem__</code>, <code>__getitem__</code> in both <code>OrigClass</code> and <code>TestClass</code>, which ones will the new <code>__dir__</code> refer to? </p></li>
  <li><p>Are there any other functions (e.g. some <code>__</code> functions such as <code>__getitem__</code>, <code>__setattr__</code> etc.) that refer to <code>__dir__</code>? Or, in other words, any chance of falling into a recursive loop if I overwrite <code>__dir__</code>?</p></li>
  </ol>