Issue2468
Created on 2016-02-17.20:08:45 by schluehk, last changed 2016-02-19.09:34:28 by schluehk.
File name |
Uploaded |
Description |
Edit |
Remove |
subtypeerasure.py
|
schluehk,
2016-02-17.20:08:44
|
|
|
|
msg10752 (view) |
Author: Kay Schluehr (schluehk) |
Date: 2016-02-17.20:08:44 |
|
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!
-------------------------------------------------------------
|
msg10758 (view) |
Author: Kay Schluehr (schluehk) |
Date: 2016-02-19.09:34:27 |
|
Only a brief note. I built Jython 2.7.1-b3 and the reported issue is still present. Actually it also was in Jython 2.5.3 so I believe it has always been there.
|
|
Date |
User |
Action |
Args |
2016-02-19 09:34:28 | schluehk | set | messages:
+ msg10758 |
2016-02-17 20:08:45 | schluehk | create | |
|