summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-10-24 19:57:45 (GMT)
committerFred Drake <fdrake@acm.org>2000-10-24 19:57:45 (GMT)
commit661ea26b3d8621ad0acc0ed2f2036ab29355f8ff (patch)
treefcfe10c4656a3e18911cd3b41b7d8c942d707786 /Objects
parentbd6f4fba1bc66a18cc15d50ffdd33faedff5ac4c (diff)
downloadcpython-661ea26b3d8621ad0acc0ed2f2036ab29355f8ff.zip
cpython-661ea26b3d8621ad0acc0ed2f2036ab29355f8ff.tar.gz
cpython-661ea26b3d8621ad0acc0ed2f2036ab29355f8ff.tar.bz2
Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c18
-rw-r--r--Objects/fileobject.c6
-rw-r--r--Objects/floatobject.c4
-rw-r--r--Objects/intobject.c10
-rw-r--r--Objects/longobject.c8
-rw-r--r--Objects/moduleobject.c27
-rw-r--r--Objects/object.c4
-rw-r--r--Objects/stringobject.c4
8 files changed, 52 insertions, 29 deletions
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 @@ class_getattr(register PyClassObject *op, PyObject *name)
}
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 @@ class_setattr(PyClassObject *op, PyObject *name, PyObject *v)
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 @@ instance_getattr1(register PyInstanceObject *inst, PyObject *name)
}
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 @@ instance_setattr1(PyInstanceObject *inst, PyObject *name, PyObject *v)
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 @@ file_readlines(PyFileObject *f, PyObject *args)
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 @@ file_writelines(PyFileObject *f, PyObject *args)
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 @@ file_writelines(PyFileObject *f, PyObject *args)
&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 @@ float_pow(PyFloatObject *v, PyObject *w, PyFloatObject *z)
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 @@ float_pow(PyFloatObject *v, PyObject *w, PyFloatObject *z)
/* 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 @@ PyInt_FromString(char *s, char **pend, int base)
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 @@ i_divmod(register PyIntObject *x, register PyIntObject *y,
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 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
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 @@ PyLong_AsLong(PyObject *vv)
overflow:
PyErr_SetString(PyExc_OverflowError,
- "long int too long to convert");
+ "long int too large to convert");
return -1;
}
@@ -204,7 +204,7 @@ PyLong_AsUnsignedLong(PyObject *vv)
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 @@ PyLong_FromString(char *str, char **pend, int base)
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 @@ long_divrem(PyLongObject *a, PyLongObject *b,
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 @@ static PyObject *
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 @@ module_getattr(PyModuleObject *m, char *name)
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 @@ module_setattr(PyModuleObject *m, char *name, PyObject *v)
}
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 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
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 @@ PyObject_Repr(PyObject *v)
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 @@ formatfloat(char *buf, size_t buflen, int flags,
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 @@ formatint(char *buf, size_t buflen, int flags,
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);