Title: Class definitions aren't provided a __module__ variable
Type: behaviour Severity: normal
Components: Core Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, pjenvey, zyasoft
Priority: Keywords:

Created on 2008-04-12.19:42:43 by pjenvey, last changed 2008-09-13.19:03:53 by zyasoft.

msg3149 (view) Author: Philip Jenvey (pjenvey) Date: 2008-04-12.19:42:42
CPython will define a __module__ attribute at the beginning of a class 
definition based on the __name__ global.

Jython 2.3a0 on java1.5.0_13
Type "copyright", "credits" or "license" for more information.
>>> class Foo(object):
...     print __module__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in Foo
NameError: name '__module__' is not defined

Python 2.5.1 (r251:54863, Aug 19 2007, 21:02:30) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
...     print __module__

CPython actually does this in the class's code object, so this is a 
compiler bug:
>>> c = compile("""\
... class Foo(object):
...     print __module__
... """, 'foo', 'exec')
>>> c.co_consts[1]
<code object Foo at 0x54d4e8, file "foo", line 1>
>>> dis.dis(c.co_consts[1])
  1           0 LOAD_NAME                0 (__name__)
              3 STORE_NAME               1 (__module__)

  2           6 LOAD_NAME                1 (__module__)
              9 PRINT_ITEM          
             10 PRINT_NEWLINE       
             11 LOAD_LOCALS         
             12 RETURN_VALUE
msg3156 (view) Author: Philip Jenvey (pjenvey) Date: 2008-04-15.18:52:13
This is slated to be fixed in the newcompiler.

This is actually the main issue in getting the pure python version of zope 
interface working on Jython:
msg3526 (view) Author: Jim Baker (zyasoft) Date: 2008-09-13.19:03:53
Fixed in r5215, __module__ is now emitted by the compiler in
Added test_class_jy.ClassDefinesDunderModule

We also test it in zope.interface
Date User Action Args
2008-09-13 19:03:53zyasoftsetstatus: open -> closed
nosy: + zyasoft
resolution: fixed
messages: + msg3526
2008-04-15 18:52:13pjenveysetmessages: + msg3156
2008-04-12 20:03:52fwierzbickisetnosy: + fwierzbicki
2008-04-12 19:42:43pjenveycreate