Title: class / function call behaviour (Jython vs. CPython)
Type: behaviour Severity: critical
Components: Core Versions: 2.1a3, 2.1b1, 2.1b2, 2.2a0, Deferred, 2.2.1rc1, 2.2beta1, 2.2.2, Jython 2.1, 2.2beta2, 2.2rc1, 2.2rc2, 2.2rc3, 2.5alpha1
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georgyberdyshev, zyasoft
Priority: Keywords:

Created on 2008-07-09.00:53:35 by georgyberdyshev, last changed 2008-09-13.22:26:58 by zyasoft.

msg3320 (view) Author: Georgy Berdyshev (georgyberdyshev) Date: 2008-07-09.00:53:33

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
msg3542 (view) Author: Jim Baker (zyasoft) Date: 2008-09-13.22:26:58
As far as I can tell, this issue has been resolved for both
zope.interface and the test code included here for determining the
'kind' of a given object (exec, module, class, function call), relying
on the fix in r5125.

See #1022
Date User Action Args
2008-09-13 22:26:58zyasoftsetstatus: open -> closed
resolution: fixed
messages: + msg3542
nosy: + zyasoft
2008-07-09 00:53:35georgyberdyshevcreate