title: how to understand this example of __getattr__ as metaclass method
body: <p>Here is a snippet of example from Mark Lutz's book "Learning Python". I found it difficult to understand as to how name accesses are translated into getattr() calls in the metaclass:</p>
  
  <pre><code>&gt;&gt;&gt; class A(type):
          def __getattr__(cls, name): 
              return getattr(cls.data, name) 
  
  &gt;&gt;&gt; class B(metaclass=A):                   
          data = 'spam'
  &gt;&gt;&gt; B.upper()
  'SPAM'
  &gt;&gt;&gt; B.upper
  &lt;built-in method upper of str object at 0x029E7420&gt;
  &gt;&gt;&gt; B.__getattr__
  &lt;bound method A.__getattr__ of &lt;class '__main__.B'&gt;&gt;
  
  &gt;&gt;&gt; B.data = [1, 2, 3]
  &gt;&gt;&gt; B.append(4)
  &gt;&gt;&gt; B.data
  [1, 2, 3, 4]
  &gt;&gt;&gt; B.__getitem__(0)
  1
  &gt;&gt;&gt; B[0]
  TypeError: 'A' object does not support indexing
  </code></pre>
  
  <p>I have the following questions:</p>
  
  <ol>
  <li><p>how does B.upper() yield 'SPAM'? Is it because B.upper() => <code>A.__getattr__(B, upper())</code> => getattr(B.data, upper())? but a call like getattr('spam', upper()) gives error "NameError: name 'upper' is not defined"</p></li>
  <li><p>what path does B.upper go to yiled <code>&lt;built-in method upper of str object at 0x029E7420&gt;</code>. does it go through getattr too, what is the true value of the arguments?</p></li>
  <li><p>Does B.append(4) go through <code>A.__getattr__(cls, name)</code>? if it does, what is the true values of the arguments in getattr(cls.data, name) in this case?</p></li>
  <li><p>how does <code>B.__getitem__(0)</code> yield 1? what is the true values of the arguments in getattr(cls.data, name) in this case?</p></li>
  </ol>