Issue1779
Created on 2011-07-25.12:06:11 by babelmania, last changed 2016-01-19.18:36:04 by zyasoft.
msg6581 (view) |
Author: Jorgo Bakker (babelmania) |
Date: 2011-07-25.12:06:10 |
|
a PyList implements List, but is not recognized as such?
See below:
---
import array
import java.util.List
b=array.array('i',[1,2,3,4,5])
a=b.tolist()
print isinstance(a,java.util.List) # False
print isinstance(a,list) # True
|
msg9344 (view) |
Author: Jim Baker (zyasoft) |
Date: 2015-01-07.08:17:25 |
|
Still the case in 2.7
|
msg10615 (view) |
Author: Jim Baker (zyasoft) |
Date: 2016-01-11.03:56:39 |
|
Naively code like the following in org.python.core.Py would work to support isinstance (with similar work for issubclass):
static boolean recursiveIsInstance(PyObject inst, PyObject cls) {
if (cls instanceof PyClass && inst instanceof PyInstance) {
...
}
if (cls instanceof PyJavaType) {
Class proxyType = ((PyJavaType) cls).getProxyType();
if (proxyType != null) {
return proxyType.isAssignableFrom(inst.getClass());
}
}
if (cls instanceof PyType) {
...
However this causes a large number of failures in the regrtest:
[exec] 10 fails unexpected:
[exec] test_dict_jy test_imaplib test_java_subclasses
[exec] test_pythoninterpreter_jy test_robotparser test_signal
[exec] test_smtpnet test_ssl test_threading_jy test_urllibnet
(Only test_ssl should be failing right now, due to other issues.)
Python and Java have two different type systems, which Jython bridges. But just because a list (as implemented by PyList) can be used where a java.util.List is expected - including in Java - doesn't mean they have the same API in Python itself.
One possibility, although I haven't thought through possible bad implications, is to support the register method from Python's abstract base classes on the Python type representing a Java interface, eg
List.register(list)
See https://docs.python.org/2/library/abc.html#abc.ABCMeta.register
I'm going to reject for now, but if we can figure out a way to make this work, we should certainly reconsider.
|
|
Date |
User |
Action |
Args |
2016-01-19 18:36:04 | zyasoft | set | status: pending -> closed |
2016-01-11 03:56:40 | zyasoft | set | status: open -> pending resolution: rejected messages:
+ msg10615 |
2015-12-29 23:49:48 | zyasoft | set | milestone: Jython 2.7.1 -> Jython 2.7.2 |
2015-04-23 03:56:11 | zyasoft | set | milestone: Jython 2.7.1 |
2015-01-07 08:17:26 | zyasoft | set | nosy:
+ zyasoft messages:
+ msg9344 versions:
+ Jython 2.7, - Jython 2.5 |
2013-02-25 19:20:47 | fwierzbicki | set | priority: low nosy:
+ fwierzbicki versions:
+ Jython 2.5, - 2.5.2 |
2011-07-25 12:06:11 | babelmania | create | |
|