Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit caf17be

Browse files
author
Michael W. Hudson
committed
I had the inheritance cycle stuff backwards. Oops!
1 parent e16e01f commit caf17be

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

Lib/test/test_descr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,6 +3452,7 @@ class E(D):
34523452
pass
34533453
d = D()
34543454
e = E()
3455+
D.__bases__ = (C,)
34553456
D.__bases__ = (C2,)
34563457
vereq(d.meth(), 1)
34573458
vereq(e.meth(), 1)
@@ -3492,6 +3493,13 @@ class L(list):
34923493
# actually, we'll have crashed by here...
34933494
raise TestFailed, "shouldn't be able to create inheritance cycles"
34943495

3496+
try:
3497+
D.__bases__ = (E,)
3498+
except TypeError:
3499+
pass
3500+
else:
3501+
raise TestFailed, "shouldn't be able to create inheritance cycles"
3502+
34953503
# let's throw a classic class into the mix:
34963504
class Classic:
34973505
def meth2(self):

Objects/typeobject.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
208208
type->tp_name, ob->ob_type->tp_name);
209209
return -1;
210210
}
211-
if (PyType_IsSubtype(type, (PyTypeObject*)ob)) {
212-
PyErr_SetString(PyExc_TypeError,
213-
"a __bases__ item causes an inheritance cycle");
214-
return -1;
211+
if (PyType_Check(ob)) {
212+
if (PyType_IsSubtype((PyTypeObject*)ob, type)) {
213+
PyErr_SetString(PyExc_TypeError,
214+
"a __bases__ item causes an inheritance cycle");
215+
return -1;
216+
}
215217
}
216218
}
217219

0 commit comments

Comments
 (0)