title: Function inside __repr__ results in infinite recursion
body: <p>I am learning Python, and I tried to code the following.</p>
  
  <pre><code>class AttributeDisplay:
      '''Display all attributes of a class in __repr__.
      It can be inherited.'''
      def gatherAttributes(self):
          '''Gather all attributes and concatenate them
          as a string'''
          def getAttributeNameAndValue(key):
              return '[%s] - [%s]' % (key, getattr(self, key))
          return '\n'.join((map(getAttributeNameAndValue, sorted(self.__dict__))))
  
      def __repr__(self):
          '''Print all attributes'''
          attr = self.gatherAttributes() # omitting () results in infinite recursion
          return '[Class: %s]\n%s' % (self.__class__.__name__, attr)
  </code></pre>
  
  <p>I accidentally omitted the parentheses and the attr becomes a function instead of a string. However, when I called the <code>print(X)</code>, it gets into the infinite recursion.</p>
  
  <p>The incorrect code is as follows.</p>
  
  <pre><code>def __repr__(self):
      '''Print all attributes'''
      attr = self.gatherAttributes # omitting () results in infinite recursion
      return '[Class: %s]\n%s' % (self.__class__.__name__, attr)
  </code></pre>
  
  <blockquote>
    <p>File "Some Folder/classtools.py", line 18, in __repr__</p>
  
  <pre><code>return '[Class: %s]\n%s' % (self.__class__.__name__, attr)
  </code></pre>
    
    <p>[Previous line repeated 244 more times]</p>
    
    <p>RecursionError: maximum recursion depth exceeded while calling a Python object</p>
  </blockquote>
  
  <p>I tried to debug but couldn't find the exact reason for this behavior. Even if I left the parentheses by accident, it should print <code>&lt;function object ...&gt;</code> right?</p>
  
  <p>Why does it call itself in <code>__repr__</code> in this case?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit: the test code is as follows.</p>
  
  <pre><code>if __name__ == '__main__':
      class TopTest(AttributeDisplay):
          count = 0
          def __init__(self):
              self.attr1 = TopTest.count
              self.attr2 = TopTest.count+1
              TopTest.count += 2
  
      class SubTest(TopTest):
          pass
  
      def test():
          t1, t2 = TopTest(), SubTest()
          print(t1)
          print(t2)
  
      test()
  </code></pre>