Message10752

Author schluehk
Recipients schluehk
Date 2016-02-17.20:08:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1455739725.77.0.678750173082.issue2468@psf.upfronthosting.co.za>
In-reply-to
Content
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!

-------------------------------------------------------------
History
Date User Action Args
2016-02-17 20:08:45schluehksetrecipients: + schluehk
2016-02-17 20:08:45schluehksetmessageid: <1455739725.77.0.678750173082.issue2468@psf.upfronthosting.co.za>
2016-02-17 20:08:45schluehklinkissue2468 messages
2016-02-17 20:08:45schluehkcreate