Author schluehk
Recipients schluehk
Date 2016-02-17.20:08:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Subclassing a primitive type (int, unicode, ... ) can cause subclass erasure when evaluated with ScriptEngine.eval(). This issue is not observed when using an instance of PythonInterpreter:

The following snippet works as expected:

import org.python.util.PythonInterpreter as PythonInterpreter

interp = PythonInterpreter()
interp.exec("class MyInt(int): pass")

print "Type MyInt expected"
interp.exec("x = MyInt(); print type(x)")  # <class '__main__.MyInt'>  -- o.k

but the following code forgets the MyInt type and returns int.

import javax.script.ScriptEngineManager as ScriptManager
import javax.script.ScriptException as ScriptException

manager = ScriptManager()
engine  = manager.getEngineByName("python")
engine.eval("class MyInt(int): pass")

print "Type MyInt expected"
engine.eval("x = MyInt(); print type(x)")  # <type 'int'>  -- not so good!

Date User Action Args
2016-02-17 20:08:45schluehksetrecipients: + schluehk
2016-02-17 20:08:45schluehksetmessageid: <>
2016-02-17 20:08:45schluehklinkissue2468 messages
2016-02-17 20:08:45schluehkcreate