Skip to content

Commit 11c785d

Browse files
committed
revert basesClasses in setSuperClass only if same like newClass
1 parent dc1a599 commit 11c785d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ public void setSuperClass(PythonAbstractClass... newBaseClasses) {
251251
this.methodResolutionOrder.setInternalArrayObject(ComputeMroNode.doSlowPath(this));
252252
this.methodResolutionOrder.lookupChanged();
253253

254-
for (PythonAbstractClass scls : subclasses) {
255-
if (scls instanceof PythonManagedClass) {
256-
PythonManagedClass pmc = (PythonManagedClass) scls;
257-
pmc.methodResolutionOrder.setInternalArrayObject(ComputeMroNode.doSlowPath(scls));
258-
pmc.methodResolutionOrder.lookupChanged();
254+
for (PythonAbstractClass scls : subclasses) {
255+
if (scls instanceof PythonManagedClass) {
256+
PythonManagedClass pmc = (PythonManagedClass) scls;
257+
pmc.methodResolutionOrder.setInternalArrayObject(ComputeMroNode.doSlowPath(scls));
258+
pmc.methodResolutionOrder.lookupChanged();
259+
}
259260
}
260-
}
261261
} catch (PException pe) {
262262
// undo
263263
for (int i = 0; i < newBaseClasses.length; i++) {
@@ -268,8 +268,12 @@ public void setSuperClass(PythonAbstractClass... newBaseClasses) {
268268
s.addAll(newBasesSubclasses.get(i));
269269
}
270270
}
271-
272-
this.baseClasses = oldBaseClasses;
271+
if (this.baseClasses == newBaseClasses) {
272+
// take no action if bases were replaced through reentrance
273+
// revert only if set in this call
274+
// e.g. the mro() call might have manipulated __bases__
275+
this.baseClasses = oldBaseClasses;
276+
}
273277
this.methodResolutionOrder.setInternalArrayObject(oldMRO);
274278
this.methodResolutionOrder.lookupChanged();
275279

0 commit comments

Comments
 (0)