From 83245b58280a7679da0fe7216f36353e44ddf859 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 12 Mar 2003 04:25:42 +0000 Subject: [PATCH] SF bug #699934: Obscure error message Clarify error message for mro conflicts. --- Lib/test/test_descr.py | 10 +++++++--- Objects/typeobject.c | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 946a529221e..d925c7585c7 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1062,6 +1062,10 @@ def consistency_with_epg(): (EditableScrollablePane, ScrollablePane, EditablePane, Pane, ScrollingMixin, EditingMixin, object)) +mro_err_msg = """Cannot create class.The superclasses have conflicting +inheritance trees which leave the method resolution order (MRO) +undefined for bases """ + def mro_disagreement(): if verbose: print "Testing error messages for MRO disagreement..." def raises(exc, expected, callable, *args): @@ -1079,9 +1083,9 @@ def mro_disagreement(): # Test some very simple errors raises(TypeError, "duplicate base class A", type, "X", (A, A), {}) - raises(TypeError, "MRO conflict among bases ", + raises(TypeError, mro_err_msg, type, "X", (A, B), {}) - raises(TypeError, "MRO conflict among bases ", + raises(TypeError, mro_err_msg, type, "X", (A, C, B), {}) # Test a slightly more complex error class GridLayout(object): pass @@ -1089,7 +1093,7 @@ def mro_disagreement(): class VerticalGrid(GridLayout): pass class HVGrid(HorizontalGrid, VerticalGrid): pass class VHGrid(VerticalGrid, HorizontalGrid): pass - raises(TypeError, "MRO conflict among bases ", + raises(TypeError, mro_err_msg, type, "ConfusedGrid", (HVGrid, VHGrid), {}) def objects(): diff --git a/Objects/typeobject.c b/Objects/typeobject.c index a067cd5963f..b0297774b5c 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1076,7 +1076,10 @@ set_mro_error(PyObject *to_merge, int *remain) } n = PyDict_Size(set); - off = PyOS_snprintf(buf, sizeof(buf), "MRO conflict among bases"); + off = PyOS_snprintf(buf, sizeof(buf), "Cannot create class.\ +The superclasses have conflicting\n\ +inheritance trees which leave the method resolution order (MRO)\n\ +undefined for bases"); i = 0; while (PyDict_Next(set, &i, &k, &v) && off < sizeof(buf)) { PyObject *name = class_name(k);