Message12416

Author jeff.allen
Recipients jeff.allen, zyasoft
Date 2019-04-01.06:35:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554100511.79.0.461447646934.issue2754@roundup.psfhosted.org>
In-reply-to
Content
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:

*** proxy_init_bug.py ***
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)

f()

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 proxy_init_bug.py
{u'a': 42, u'b': 42, u'c': 42}
Traceback (most recent call last):
  File "proxy_init_bug.py", line 10, in <module>
    f()
  File "proxy_init_bug.py", line 8, in f
    print D.fromkeys('abc', 42)
AttributeError: 'module' object has no attribute 'D'
History
Date User Action Args
2019-04-01 06:35:11jeff.allensetrecipients: + jeff.allen, zyasoft
2019-04-01 06:35:11jeff.allensetmessageid: <1554100511.79.0.461447646934.issue2754@roundup.psfhosted.org>
2019-04-01 06:35:11jeff.allenlinkissue2754 messages
2019-04-01 06:35:11jeff.allencreate