Author georgyberdyshev
Recipients georgyberdyshev
Date 2008-07-09.00:53:33
SpamBayes Score 0.0387943
Marked as misclassified No
Message-id <>

At the moment Jython represents several calls to classes
as function calls. 

Here is some output of CPython 2.5 and Jython svn asm branch r4826:

gebe@venus:~/work/crash$ python
f_locals:  {'__module__': '__main__', 'classLevelFrameInfo': ('class',
<module '__main__' from ''>, {...}, {'kind': 'class',
'f_globals': {...}, 'frameInfo': <function frameInfo at 0xb7d2ad84>,
'__builtins__': <module '__builtin__' (built-in)>, 'ClassType': <type
'classobj'>, '__file__': '', 'module': <module '__main__' from
''>, 'f_locals': {...}, 'sys': <module 'sys' (built-in)>,
'ClassicClass': <class __main__.ClassicClass at 0xb7d3465c>, '__name__':
'__main__', '__doc__': None}), '__doc__': None}

f_globals:  {'kind': 'class', 'f_globals': {...}, 'frameInfo': <function
frameInfo at 0xb7d2ad84>, '__builtins__': <module
'__builtin__' (built-in)>, 'ClassType': <type 'classobj'>, '__file__':
'', 'module': <module '__main__' from ''>, 'f_locals':
{'__module__': '__main__', 'classLevelFrameInfo': ('class', <module
'__main__' from ''>, {...}, {...}), '__doc__': None}, 'sys':
<module 'sys' (built-in)>, 'ClassicClass': <class __main__.ClassicClass
at 0xb7d3465c>, '__name__': '__main__', '__doc__': None}

gebe@venus:~/work/crash$ jython25
function call
f_locals:  {'__doc__': None, '__module__': '__main__',
'classLevelFrameInfo': ('function call', <module '__main__' from
''>, {...}, {'ClassicClass': <class __main__.ClassicClass at 1>,
'sys': sys module, '__file__': '', '__doc__': None, 'f_globals':
{...}, 'frameInfo': <function frameInfo at 2>, 'kind': 'function call',
'__name__': '__main__', 'f_locals': {...}, 'ClassType': <type 'class'>,
'module': <module '__main__' from ''>})}

f_globals:  {'ClassicClass': <class __main__.ClassicClass at 1>, 'sys':
sys module, '__file__': '', '__doc__': None, 'f_globals': {...},
'frameInfo': <function frameInfo at 2>, 'kind': 'function call',
'__name__': '__main__', 'f_locals': {'__doc__': None, '__module__':
'__main__', 'classLevelFrameInfo': ('function call', <module '__main__'
from ''>, {...}, {...})}, 'ClassType': <type 'class'>, 'module':
<module '__main__' from ''>}

The code is a modified version of the parts for testing included in

gebe@venus:~/work/crash$ cat
from myimport import *

from types import ClassType

class ClassicClass:
    classLevelFrameInfo = frameInfo(sys._getframe())

kind, module, f_locals, f_globals = ClassicClass.classLevelFrameInfo

print kind
print "*" * 20
print "f_locals: ", f_locals
print "f_globals: ", f_globals


gebe@venus:~/work/crash$ cat
import sys

def frameInfo(frame):
    f_locals = frame.f_locals
    f_globals = frame.f_globals

    sameNamespace = f_locals is f_globals
    hasModule = '__module__' in f_locals
    hasName = '__name__' in f_globals

    sameName = hasModule and hasName
    sameName =sameName and f_globals['__name__']==f_locals['__module__']

    module = hasName and sys.modules.get(f_globals['__name__']) or None

    namespaceIsModule = module and module.__dict__ is f_globals

    if not namespaceIsModule:
        kind = "exec"
    elif sameNamespace and not hasModule:
        kind = "module"
    elif sameName and not sameNamespace:
        kind = "class"
    elif not sameNamespace:
        kind = "function call"

        kind = "unknown"
    return kind, module, f_locals, f_globals
Date User Action Args
2008-07-09 00:53:35georgyberdyshevsetspambayes_score: 0.0387943 -> 0.0387943
recipients: + georgyberdyshev
2008-07-09 00:53:35georgyberdyshevsetspambayes_score: 0.0387943 -> 0.0387943
messageid: <>
2008-07-09 00:53:35georgyberdyshevlinkissue1067 messages
2008-07-09 00:53:34georgyberdyshevcreate