Title: Failure in Py.initProxy for class not at module level
Type: crash Severity: normal
Components: Core Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, zyasoft
Priority: normal Keywords:

Created on 2019-04-01.06:35:11 by jeff.allen, last changed 2019-04-01.06:35:11 by jeff.allen.

msg12416 (view) Author: Jeff Allen (jeff.allen) Date: 2019-04-01.06:35:11
I came across this trying to increase test coverage under #2746, but I think it is not specifically about mapping types but something I don't properly understand about proxies.

When a proxy type sub-class is not a global variable, it is not found when Py.initProxy is called from code generated by org.python.compiler.JavaMaker.addProxy(). Py.initProxy is supplied a module name and a (simple) class name, but then it looks in that module for the name as an attribute, which may not be where it is. This simple program reproduces it the probjem:

*** ***
from java.util import HashMap

class C(HashMap): pass
print C.fromkeys('abc', 42) # works

def f():
    class D(HashMap): pass
    print D.fromkeys('abc', 42)


The part involving class C is only there to demonstrate that it works correctly at the top level. The attempt by Py.initProxy to look-up D in __main__ produces a confusing message:

PS jython-jvm9> dist\bin\jython
{u'a': 42, u'b': 42, u'c': 42}
Traceback (most recent call last):
  File "", line 10, in <module>
  File "", line 8, in f
    print D.fromkeys('abc', 42)
AttributeError: 'module' object has no attribute 'D'
Date User Action Args
2019-04-01 06:35:11jeff.allencreate