Message10752
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:45 | schluehk | set | recipients:
+ schluehk |
2016-02-17 20:08:45 | schluehk | set | messageid: <1455739725.77.0.678750173082.issue2468@psf.upfronthosting.co.za> |
2016-02-17 20:08:45 | schluehk | link | issue2468 messages |
2016-02-17 20:08:45 | schluehk | create | |
|