Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity.

This (mostly) closes SourceForge patch #101839.
diff --git a/Objects/classobject.c b/Objects/classobject.c
index c362b80..1c9cd7e 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -173,7 +173,9 @@
 	}
 	v = class_lookup(op, name, &class);
 	if (v == NULL) {
-		PyErr_SetObject(PyExc_AttributeError, name);
+		PyErr_Format(PyExc_AttributeError,
+			     "class %.50s has no attribute '%.400s'",
+			     PyString_AS_STRING(op->cl_name), sname);
 		return NULL;
 	}
 	Py_INCREF(v);
@@ -285,8 +287,9 @@
 	if (v == NULL) {
 		int rv = PyDict_DelItem(op->cl_dict, name);
 		if (rv < 0)
-			PyErr_SetString(PyExc_AttributeError,
-				   "delete non-existing class attribute");
+			PyErr_Format(PyExc_AttributeError,
+				     "class %.50s has no attribute '%.400s'",
+				     PyString_AS_STRING(op->cl_name), sname);
 		return rv;
 	}
 	else
@@ -578,7 +581,8 @@
 	}
 	v = instance_getattr2(inst, name);
 	if (v == NULL) {
-		PyErr_Format(PyExc_AttributeError,"'%.50s' instance has no attribute '%.400s'",
+		PyErr_Format(PyExc_AttributeError,
+			     "%.50s instance has no attribute '%.400s'",
 			     PyString_AS_STRING(inst->in_class->cl_name), sname);
 	}
 	return v;
@@ -642,8 +646,10 @@
 	if (v == NULL) {
 		int rv = PyDict_DelItem(inst->in_dict, name);
 		if (rv < 0)
-			PyErr_SetString(PyExc_AttributeError,
-				   "delete non-existing instance attribute");
+			PyErr_Format(PyExc_AttributeError,
+				     "%.50s instance has no attribute '%.400s'",
+				     PyString_AS_STRING(inst->in_class->cl_name),
+				     PyString_AS_STRING(name));
 		return rv;
 	}
 	else
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index b8b47f8..94c5bb0 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -833,7 +833,7 @@
 			buffersize *= 2;
 			if (buffersize > INT_MAX) {
 				PyErr_SetString(PyExc_OverflowError,
-					"line is too long for a Python string");
+					"line is longer than a Python string can hold");
 				goto error;
 			}
 			if (big_buffer == NULL) {
@@ -938,7 +938,7 @@
 		return err_closed();
 	if (args == NULL || !PySequence_Check(args)) {
 		PyErr_SetString(PyExc_TypeError,
-			   "writelines() requires sequence of strings");
+			   "writelines() argument must be a sequence of strings");
 		return NULL;
 	}
 	islist = PyList_Check(args);
@@ -1001,7 +1001,7 @@
 							   &buffer,
 							   &len))) {
 					PyErr_SetString(PyExc_TypeError,
-				"writelines() requires sequences of strings");
+				"writelines() argument must be a sequence of strings");
 					goto error;
 				}
 				line = PyString_FromStringAndSize(buffer,
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d776147..b58c7fd 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -466,7 +466,7 @@
 	if (iv == 0.0) {
 		if (iw < 0.0) {
 			PyErr_SetString(PyExc_ZeroDivisionError,
-				   "0.0 to a negative power");
+					"0.0 cannot be raised to a negative power");
 			return NULL;
 		}
 		return PyFloat_FromDouble(0.0);
@@ -486,7 +486,7 @@
 		/* Sort out special cases here instead of relying on pow() */
 		if (iv < 0.0) {
 			PyErr_SetString(PyExc_ValueError,
-				   "negative number to a float power");
+					"negative number cannot be raised to a fractional power");
 			return NULL;
 		}
 		errno = 0;
diff --git a/Objects/intobject.c b/Objects/intobject.c
index c9d1f6a..18acf6b 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -171,7 +171,7 @@
 	char buffer[256]; /* For errors */
 
 	if ((base != 0 && base < 2) || base > 36) {
-		PyErr_SetString(PyExc_ValueError, "invalid base for int()");
+		PyErr_SetString(PyExc_ValueError, "int() base must be >= 2 and <= 36");
 		return NULL;
 	}
 
@@ -417,7 +417,7 @@
 	
 	if (yi == 0) {
 		PyErr_SetString(PyExc_ZeroDivisionError,
-				"integer division or modulo");
+				"integer division or modulo by zero");
 		return -1;
 	}
 	if (yi < 0) {
@@ -485,17 +485,17 @@
 	if (iw < 0) {
 		if (iv)
 			PyErr_SetString(PyExc_ValueError,
-					"integer to a negative power");
+					"cannot raise integer to a negative power");
 		else
 			PyErr_SetString(PyExc_ZeroDivisionError,
-					"0 to a negative power");
+					"cannot raise 0 to a negative power");
 		return NULL;
 	}
  	if ((PyObject *)z != Py_None) {
 		iz = z->ob_ival;
 		if (iz == 0) {
 			PyErr_SetString(PyExc_ValueError,
-					"pow(x, y, z) with z==0");
+					"pow() arg 3 cannot be 0");
 			return NULL;
 		}
 	}
diff --git a/Objects/longobject.c b/Objects/longobject.c
index bfb431f..615d1d8 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -173,7 +173,7 @@
 
  overflow:
 	PyErr_SetString(PyExc_OverflowError,
-			"long int too long to convert");
+			"long int too large to convert");
 	return -1;
 }
 
@@ -204,7 +204,7 @@
 		x = (x << SHIFT) + v->ob_digit[i];
 		if ((x >> SHIFT) != prev) {
 			PyErr_SetString(PyExc_OverflowError,
-				"long int too long to convert");
+				"long int too large to convert");
 			return (unsigned long) -1;
 		}
 	}
@@ -653,7 +653,7 @@
 	
 	if ((base != 0 && base < 2) || base > 36) {
 		PyErr_SetString(PyExc_ValueError,
-				"invalid base for long literal");
+				"long() arg 2 must be >= 2 and <= 36");
 		return NULL;
 	}
 	while (*str != '\0' && isspace(Py_CHARMASK(*str)))
@@ -751,7 +751,7 @@
 	
 	if (size_b == 0) {
 		PyErr_SetString(PyExc_ZeroDivisionError,
-				"long division or modulo");
+				"long division or modulo by zero");
 		return -1;
 	}
 	if (size_a < size_b ||
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index c655e95..4267896 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -163,13 +163,22 @@
 module_getattr(PyModuleObject *m, char *name)
 {
 	PyObject *res;
+	char* modname;
 	if (strcmp(name, "__dict__") == 0) {
 		Py_INCREF(m->md_dict);
 		return m->md_dict;
 	}
 	res = PyDict_GetItemString(m->md_dict, name);
-	if (res == NULL)
-		PyErr_SetString(PyExc_AttributeError, name);
+	if (res == NULL) {
+		modname = PyModule_GetName((PyObject *)m);
+		if (modname == NULL) {
+			PyErr_Clear();
+			modname = "?";
+		}
+		PyErr_Format(PyExc_AttributeError,
+			     "'%.50s' module has no attribute '%.400s'",
+			     modname, name);
+	}
 	else
 		Py_INCREF(res);
 	return res;
@@ -178,6 +187,7 @@
 static int
 module_setattr(PyModuleObject *m, char *name, PyObject *v)
 {
+	char* modname;
 	if (name[0] == '_' && strcmp(name, "__dict__") == 0) {
 		PyErr_SetString(PyExc_TypeError,
 				"read-only special attribute");
@@ -185,9 +195,16 @@
 	}
 	if (v == NULL) {
 		int rv = PyDict_DelItemString(m->md_dict, name);
-		if (rv < 0)
-			PyErr_SetString(PyExc_AttributeError,
-				   "delete non-existing module attribute");
+		if (rv < 0) {
+			modname = PyModule_GetName((PyObject *)m);
+			if (modname == NULL) {
+				PyErr_Clear();
+				modname = "?";
+			}
+			PyErr_Format(PyExc_AttributeError,
+				     "'%.50s' module has no attribute '%.400s'",
+				     modname, name);
+		}
 		return rv;
 	}
 	else
diff --git a/Objects/object.c b/Objects/object.c
index 9b7c551..6f22c53 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -175,7 +175,7 @@
 		return -1;
 #ifdef USE_STACKCHECK
 	if (PyOS_CheckStack()) {
-		PyErr_SetString(PyExc_MemoryError, "Stack overflow");
+		PyErr_SetString(PyExc_MemoryError, "stack overflow");
 		return -1;
 	}
 #endif
@@ -227,7 +227,7 @@
 		return NULL;
 #ifdef USE_STACKCHECK
 	if (PyOS_CheckStack()) {
-		PyErr_SetString(PyExc_MemoryError, "Stack overflow");
+		PyErr_SetString(PyExc_MemoryError, "stack overflow");
 		return NULL;
 	}
 #endif
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index dbade8c..757c1c4 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -2460,7 +2460,7 @@
 	   always given), therefore increase by one to 10+prec. */
 	if (buflen <= (size_t)10 + (size_t)prec) {
 		PyErr_SetString(PyExc_OverflowError,
-			"formatted float is too long (precision too long?)");
+			"formatted float is too long (precision too large?)");
 		return -1;
 	}
 	sprintf(buf, fmt, x);
@@ -2626,7 +2626,7 @@
 	   worst case buf = '0x' + [0-9]*prec, where prec >= 11 */
 	if (buflen <= 13 || buflen <= (size_t)2 + (size_t)prec) {
 		PyErr_SetString(PyExc_OverflowError,
-			"formatted integer is too long (precision too long?)");
+			"formatted integer is too long (precision too large?)");
 		return -1;
 	}
 	sprintf(buf, fmt, x);