Message8317
Demo:
$ java -jar jython.jar
Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_55
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.Global(['x', 'y'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
java.lang.ClassCastException: java.lang.String cannot be cast to org.python.core.PyObject
at org.python.antlr.adapter.IdentifierAdapter.iter2ast(IdentifierAdapter.java:30)
at org.python.antlr.adapter.AstAdapters.py2identifierList(AstAdapters.java:44)
at org.python.antlr.ast.Global.setNames(Global.java:41)
at org.python.antlr.ast.Global.Global___init__(Global.java:69)
at org.python.antlr.ast.Global$exposed___new__.createOfType(Unknown Source)
at org.python.core.PyOverridableNew.new_impl(PyOverridableNew.java:12)
at org.python.core.PyType.invokeNew(PyType.java:480)
at org.python.core.PyType.type___call__(PyType.java:1638)
at org.python.core.PyType.__call__(PyType.java:1628)
at org.python.core.PyObject.__call__(PyObject.java:403)
at org.python.core.PyObject.__call__(PyObject.java:407)
at org.python.pycode._pyx2.f$0(<stdin>:1)
at org.python.pycode._pyx2.call_function(<stdin>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1302)
at org.python.core.Py.exec(Py.java:1346)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215)
at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:46)
at org.python.util.InteractiveConsole.push(InteractiveConsole.java:110)
at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:90)
at org.python.util.jython.run(jython.java:378)
at org.python.util.jython.main(jython.java:137)
java.lang.ClassCastException: java.lang.ClassCastException: java.lang.String cannot be cast to org.python.core.PyObject
Workaround on the Java end:
builtins.__setitem__("__astglobal__", new PyObject() {
@Override
public PyObject __call__(final PyObject names) {
final List<String> newNames = new ArrayList<String>();
for (final Object o : names.asIterable()) {
newNames.add(o.toString());
}
final Global glowball = new Global();
try {
final Field namesField = Global.class.getDeclaredField("names");
namesField.setAccessible(true);
namesField.set(glowball, newNames);
return glowball;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
}); |
|
Date |
User |
Action |
Args |
2014-05-01 13:14:09 | JonathanFeinberg | set | recipients:
+ JonathanFeinberg |
2014-05-01 13:14:09 | JonathanFeinberg | set | messageid: <1398950049.87.0.792955678348.issue2134@psf.upfronthosting.co.za> |
2014-05-01 13:14:09 | JonathanFeinberg | link | issue2134 messages |
2014-05-01 13:14:08 | JonathanFeinberg | create | |
|