title: Python metaclasses: Why isn't __setattr__ called for attributes set during class definition?
body: <p>I have the following python code:</p>
  
  <pre><code>class FooMeta(type):
      def __setattr__(self, name, value):
          print name, value
          return super(FooMeta, self).__setattr__(name, value)
  
  class Foo(object):
      __metaclass__ = FooMeta
      FOO = 123
      def a(self):
          pass
  </code></pre>
  
  <p>I would have expected <code>__setattr__</code> of the meta class being called for both <code>FOO</code> and <code>a</code>. However, it is not called at all. When I assign something to <code>Foo.whatever</code> after the class has been defined the method <em>is</em> called.</p>
  
  <p>What's the reason for this behaviour and is there a way to intercept the assignments that happen during the creation of the class? Using <code>attrs</code> in <code>__new__</code> won't work since I'd like to <a href="https://stackoverflow.com/q/10761988/298479">check if a method is being redefined</a>.</p>