[Jython-checkins] jython: Next method resolution for super on __init__ should call the
jim.baker
jython-checkins at python.org
Wed Sep 2 01:37:42 CEST 2015
https://hg.python.org/jython/rev/406ca703d7d3
changeset: 7718:406ca703d7d3
user: Darjus Loktevic <darjus at gmail.com>
date: Tue Sep 01 17:37:34 2015 -0600
summary:
Next method resolution for super on __init__ should call the
corresponding Java constructor when the MRO contains a Java type
proxy.
Fixes http://bugs.jython.org/issue2375
files:
Lib/test/test_java_subclasses.py | 21 ++++++++++++++++++++
src/org/python/core/PyType.java | 4 ++-
2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_java_subclasses.py b/Lib/test/test_java_subclasses.py
--- a/Lib/test/test_java_subclasses.py
+++ b/Lib/test/test_java_subclasses.py
@@ -14,6 +14,7 @@
from java.awt import Color, Component, Dimension, Rectangle
from javax.swing import ComboBoxModel, ListModel
from javax.swing.table import AbstractTableModel
+from javax.swing.tree import DefaultTreeModel, DefaultMutableTreeNode
from org.python.tests import BeanInterface, Callbacker, Coercions, OwnMethodCaller
from javatests import (
@@ -625,6 +626,25 @@
self.assertFalse(thread.isAlive())
+class OldAndNewStyleInitSuperTest(unittest.TestCase):
+ """
+ http://bugs.jython.org/issue2375
+ """
+
+ def test_new_style_init(self):
+ class AModel(DefaultTreeModel):
+ def __init__(self):
+ super(AModel, self).__init__(DefaultMutableTreeNode())
+
+ AModel()
+
+ def test_old_style_init(self):
+ class AModel(DefaultTreeModel):
+ def __init__(self):
+ DefaultTreeModel.__init__(self, DefaultMutableTreeNode())
+
+ AModel()
+
def test_main():
test_support.run_unittest(
InterfaceTest,
@@ -636,6 +656,7 @@
MetaClassTest,
AbstractMethodTest,
SuperIsSuperTest,
+ OldAndNewStyleInitSuperTest,
HierarchyTest,
ChooseCorrectToJavaTest)
diff --git a/src/org/python/core/PyType.java b/src/org/python/core/PyType.java
--- a/src/org/python/core/PyType.java
+++ b/src/org/python/core/PyType.java
@@ -1303,7 +1303,9 @@
// So break out of this infinite loop by ignoring this entry for super purposes.
// The use of super__ parallels the workaround seen in PyReflectedFunction
// Fixes http://bugs.jython.org/issue1540
- if(!name.startsWith("super__")) {
+ // Also ignore this if we're doing super during __init__ as we want it to behave
+ // Fixes http://bugs.jython.org/issue2375
+ if(name != "__init__" && !name.startsWith("super__")) {
lookupName = "super__" + name;
} else {
lookupName = name;
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list