Issue2134

classification
Title: Cannot create an instance of ast.Global using constructor that takes names
Type: crash Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
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.

Messages
msg8317 (view) Author: Jonathan Feinberg (JonathanFeinberg) Date: 2014-05-01.13:14:08
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);
        }
      }
    });
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?
History
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