title: Inherit or mock pythons etree.ElementTree.Element possible?
body: <p>I'm trying to create a small addon for <code>ElementTree</code> and <code>Element</code> in python's <code>xml.etree.ElementTree</code> which would allow for notation like:</p>
  
  <pre><code>root = ET.fromstring('&lt;root&gt;&lt;a&gt;&lt;b attr1="2"/&gt;&lt;/a&gt;&lt;/root&gt;')
  element1 = root.a
  element2 = root.a.b
  attr = root.a.b.attr
  </code></pre>
  
  <p>I've tried this:</p>
  
  <pre><code>import xml.etree.ElementTree as _ET
  
  def __getattr__(self, key):
      return self.find('./' + key)
  
  class ElementTree(_ET.ElementTree):
      __getattr__ = __getattr__
  
  
  class Element(_ET.Element):
      __getattr__ = __getattr__
  </code></pre>
  
  <p>But this does not work because <code>ET.parse</code>, <code>ET.fromstring</code>, <code>ET.ElementTree.find</code> etc will always return the internal <code>Element</code> and <code>ElementTree</code> objects.</p>
  
  <p>Monkeypatching the classes does not work either:</p>
  
  <pre><code>&gt;&gt;&gt; xml.etree.ElementTree.Element.__getattr__ = lambda x: x
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-4-bacb0a64c2e5&gt; in &lt;module&gt;()
  ----&gt; 1 xml.etree.ElementTree.Element.__getattr__ = lambda x: x
  
  TypeError: can't set attributes of built-in/extension type 'xml.etree.ElementTree.Element'
  </code></pre>
  
  <p>Is this doable without copying the python etree module and then adding <code>__getattr__</code>?</p>
  
  <p>Related: <a href="https://stackoverflow.com/questions/22243529/how-to-inherit-elementtree-element-class-in-python">How to inherit ElementTree.Element class in python?</a></p>