Message10667
[DESCRIPTION]
The following problem is a regression in Jython 2.7.0 with respect to Jython 2.5.2.
Download the attached jar file and unpack it -alternatively, add it to the classpath, or by means of sys.path.append("examples.jar")-.
Here are the contents:
herl55:~> jar tvf examples.jar
0 Fri Jan 22 09:06:28 CET 2016 META-INF/
68 Fri Jan 22 09:06:28 CET 2016 META-INF/MANIFEST.MF
0 Fri Jan 22 08:55:26 CET 2016 example1/
47 Fri Jan 22 08:55:20 CET 2016 example1/SomeClass.java
201 Fri Jan 22 08:55:26 CET 2016 example1/SomeClass.class
0 Fri Jan 22 08:59:52 CET 2016 example2/
2014 Fri Jan 22 09:01:54 CET 2016 example2/__init__$py.class
0 Thu Jan 21 18:47:10 CET 2016 example2/__init__.py
203 Fri Jan 22 08:56:18 CET 2016 example2/OtherClass.class
48 Fri Jan 22 08:56:10 CET 2016 example2/OtherClass.java
Basically, it has two classes, in different packages, one of which has also a __init__.py file.
With Jython 2.5.2, the following works:
herl55:~> jython2.5
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> import example1
>>> import example2
>>> print example1.SomeClass
<type 'example1.SomeClass'>
>>> print example2.OtherClass
<type 'example2.OtherClass'>
The second print fails, however, with Jython 2.7.0:
herl55:~> jython2.7
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> import example1
>>> import example2
>>> print example1.SomeClass
<type 'example1.SomeClass'>
>>> print example2.OtherClass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'OtherClass'
[DIAGNOSIS]
While example1 is represented in Jython by a PyJavaPackage, example2 is loaded as a PyModule (I suppose because of the __init__.py file). This is the case in both Jython versions.
The last element of the path (OtherClass) is tried to be determined
as an attribute of example2, by calling __findattr_ex__ on it.
The method PyObject.__findattr_ex__ looks up the name in a local dictionary of attributes. "OtherClass" is not found there.
In Jython 2.5.2, PyModule overrides __findattr_ex__ to call impAttr if super.__findattr_ex__ returns null. This is when it finds OtherClass by importing it.
However, in Jython 2.7.0 this overriding version of __findattr_ex__ has been deleted from PyModule. Then PyObject.__findattr_ex__ is directly called, so OtherClass is not found.
[SOLUTION]
Recover the deleted method PyModule.__findattr_ex__, as it was in version 2.5.2:
@Override
public PyObject __findattr_ex__(String name) {
PyObject attr=super.__findattr_ex__(name);
if (attr!=null)
return attr;
return impAttr(name);
} |
|
Date |
User |
Action |
Args |
2016-01-22 08:46:57 | jsaiz | set | recipients:
+ jsaiz |
2016-01-22 08:46:57 | jsaiz | set | messageid: <1453452417.51.0.0500527575226.issue2455@psf.upfronthosting.co.za> |
2016-01-22 08:46:57 | jsaiz | link | issue2455 messages |
2016-01-22 08:46:55 | jsaiz | create | |
|