title: Is "__module__" guaranteed to be defined during class creation?
body: <p>I was reading some code that looked basically like this:</p>
  
  <pre><code>class Foo(object):
      class_name = __module__.replace('_', '-')
  </code></pre>
  
  <p>To me, that looked really weird (<code>__module__</code>, what is that?) so I went and looked at the python <a href="https://docs.python.org/2/reference/datamodel.html">data-model</a>.  A quick search shows that <code>__module__</code> is a property of class objects and of function objects.  However, there is no <code>__module__</code> available in the global namespace (as can easily be verified by just trying to look at it and observing the <code>NameError</code> that results ...).</p>
  
  <p>I decided to chalk this up to implementation specific behavior, but as a last check, I decided to test with other implementations I have handy.  It turns out that this code executes with<sup>1</sup></p>
  
  <ul>
  <li>Cpython 2.7.6</li>
  <li>Cpython 3.4.0</li>
  <li>jython 2.5.3</li>
  <li>PyPy 2.2.1 (Python 2.7.3)</li>
  </ul>
  
  <p>My question is whether this behavior is actually defined anywhere in the language reference.  I'm not sure why I'd want to, but could I safely rely on <code>__module__</code> being in the class creation namespace or did all the implementors just decide to do this the same way?</p>
  
  <p><sup><sup>1</sup>All linux, but I doubt that matters ...</sup></p>