From: Philip J. <re...@bu...> - 2008-04-12 19:42:47
|
New submission from Philip Jenvey <pj...@us...>: 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__ ... __main__ >>> 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 ---------- components: Core messages: 3149 nosy: pjenvey severity: normal status: open title: Class definitions aren't provided a __module__ variable type: behaviour _______________________________________ Jython tracker <re...@bu...> <http://bugs.jython.org/issue1022> _______________________________________ |