Title: Cannot create an instance of ast.Global using constructor that takes names
Type: crash Severity: normal
Components: Core Versions: Jython 2.7
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: JonathanFeinberg, fwierzbicki, zyasoft
Priority: normal Keywords:

Created on 2014-05-01.13:14:09 by JonathanFeinberg, last changed 2014-10-07.00:16:08 by zyasoft.

msg8317 (view) Author: Jonathan Feinberg (JonathanFeinberg) Date: 2014-05-01.13:14:08

$ 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(
	at org.python.antlr.adapter.AstAdapters.py2identifierList(
	at org.python.antlr.ast.Global.setNames(
	at org.python.antlr.ast.Global.Global___init__(
	at org.python.antlr.ast.Global$exposed___new__.createOfType(Unknown Source)
	at org.python.core.PyOverridableNew.new_impl(
	at org.python.core.PyType.invokeNew(
	at org.python.core.PyType.type___call__(
	at org.python.core.PyType.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.pycode._pyx2.f$0(<stdin>:1)
	at org.python.pycode._pyx2.call_function(<stdin>)
	at org.python.core.Py.runCode(
	at org.python.core.Py.exec(
	at org.python.util.PythonInterpreter.exec(
	at org.python.util.InteractiveInterpreter.runcode(
	at org.python.util.InteractiveInterpreter.runsource(
	at org.python.util.InteractiveInterpreter.runsource(
	at org.python.util.InteractiveConsole.push(
	at org.python.util.InteractiveConsole.interact(
	at org.python.util.jython.main(

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() {
      public PyObject __call__(final PyObject names) {
        final List<String> newNames = new ArrayList<String>();
        for (final Object o : names.asIterable()) {
        final Global glowball = new Global();
        try {
          final Field namesField = Global.class.getDeclaredField("names");
          namesField.set(glowball, newNames);
          return glowball;
        } catch (final Exception e) {
          throw new RuntimeException(e);
msg8835 (view) Author: Jim Baker (zyasoft) Date: 2014-06-28.04:00:03
Target beta 4
msg9089 (view) Author: Jim Baker (zyasoft) Date: 2014-10-06.03:12:09
Frank, any chance we get this in for beta 4? Or we will have to let this slip to 2.7.1 or later?
Date User Action Args
2014-10-07 00:16:08zyasoftsetpriority: normal
2014-10-06 03:12:10zyasoftsetmessages: + msg9089
2014-06-28 04:00:03zyasoftsetmessages: + msg8835
2014-05-21 23:16:28zyasoftsetnosy: + fwierzbicki, zyasoft
resolution: accepted
2014-05-01 13:14:09JonathanFeinbergcreate