mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
(Modified) patch by Ping - SF Patch #102681.
- Make error messages from issubclass() and isinstance() a bit more descriptive (Ping, modified by Guido) - Couple of tiny fixes to other docstrings (Ping) - Get rid of trailing whitespace (Guido)
This commit is contained in:
parent
234fb632a3
commit
ad991775ab
1 changed files with 33 additions and 27 deletions
|
@ -114,7 +114,7 @@ builtin_buffer(PyObject *self, PyObject *args)
|
||||||
static char buffer_doc[] =
|
static char buffer_doc[] =
|
||||||
"buffer(object [, offset[, size]]) -> object\n\
|
"buffer(object [, offset[, size]]) -> object\n\
|
||||||
\n\
|
\n\
|
||||||
Creates a new buffer object which references the given object.\n\
|
Create a new buffer object which references the given object.\n\
|
||||||
The buffer will reference a slice of the target object from the\n\
|
The buffer will reference a slice of the target object from the\n\
|
||||||
start of the object (or at the specified offset). The slice will\n\
|
start of the object (or at the specified offset). The slice will\n\
|
||||||
extend to the end of the target object (or with the specified size).";
|
extend to the end of the target object (or with the specified size).";
|
||||||
|
@ -135,7 +135,7 @@ builtin_unicode(PyObject *self, PyObject *args)
|
||||||
static char unicode_doc[] =
|
static char unicode_doc[] =
|
||||||
"unicode(string [, encoding[, errors]]) -> object\n\
|
"unicode(string [, encoding[, errors]]) -> object\n\
|
||||||
\n\
|
\n\
|
||||||
Creates a new Unicode object from the given encoded string.\n\
|
Create a new Unicode object from the given encoded string.\n\
|
||||||
encoding defaults to the current default string encoding and \n\
|
encoding defaults to the current default string encoding and \n\
|
||||||
errors, defining the error handling, to 'strict'.";
|
errors, defining the error handling, to 'strict'.";
|
||||||
|
|
||||||
|
@ -411,9 +411,9 @@ complex_from_string(PyObject *v)
|
||||||
"complex() literal too large to convert");
|
"complex() literal too large to convert");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
|
if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
|
||||||
PyUnicode_GET_SIZE(v),
|
PyUnicode_GET_SIZE(v),
|
||||||
s_buffer,
|
s_buffer,
|
||||||
NULL))
|
NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
s = s_buffer;
|
s = s_buffer;
|
||||||
|
@ -438,7 +438,7 @@ complex_from_string(PyObject *v)
|
||||||
z = -1.0;
|
z = -1.0;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
do {
|
do {
|
||||||
|
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
|
|
||||||
case '\0':
|
case '\0':
|
||||||
|
@ -450,7 +450,7 @@ complex_from_string(PyObject *v)
|
||||||
}
|
}
|
||||||
if(!done) sw_error=1;
|
if(!done) sw_error=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
sign = -1;
|
sign = -1;
|
||||||
/* Fallthrough */
|
/* Fallthrough */
|
||||||
|
@ -509,7 +509,7 @@ complex_from_string(PyObject *v)
|
||||||
}
|
}
|
||||||
s=end;
|
s=end;
|
||||||
if (*s=='J' || *s=='j') {
|
if (*s=='J' || *s=='j') {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (got_re) {
|
if (got_re) {
|
||||||
|
@ -524,7 +524,7 @@ complex_from_string(PyObject *v)
|
||||||
z = -1.0;
|
z = -1.0;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} /* end of switch */
|
} /* end of switch */
|
||||||
|
|
||||||
} while (*s!='\0' && !sw_error);
|
} while (*s!='\0' && !sw_error);
|
||||||
|
@ -935,7 +935,7 @@ builtin_map(PyObject *self, PyObject *args)
|
||||||
for (len = 0, i = 0, sqp = seqs; i < n; ++i, ++sqp) {
|
for (len = 0, i = 0, sqp = seqs; i < n; ++i, ++sqp) {
|
||||||
int curlen;
|
int curlen;
|
||||||
PySequenceMethods *sqf;
|
PySequenceMethods *sqf;
|
||||||
|
|
||||||
if ((sqp->seq = PyTuple_GetItem(args, i + 1)) == NULL)
|
if ((sqp->seq = PyTuple_GetItem(args, i + 1)) == NULL)
|
||||||
goto Fail_2;
|
goto Fail_2;
|
||||||
|
|
||||||
|
@ -1135,7 +1135,7 @@ builtin_hex(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O:hex", &v))
|
if (!PyArg_ParseTuple(args, "O:hex", &v))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((nb = v->ob_type->tp_as_number) == NULL ||
|
if ((nb = v->ob_type->tp_as_number) == NULL ||
|
||||||
nb->nb_hex == NULL) {
|
nb->nb_hex == NULL) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -1244,7 +1244,7 @@ builtin_long(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
int base = -909; /* unlikely! */
|
int base = -909; /* unlikely! */
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|i:long", &v, &base))
|
if (!PyArg_ParseTuple(args, "O|i:long", &v, &base))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (base == -909)
|
if (base == -909)
|
||||||
|
@ -1529,7 +1529,7 @@ builtin_ord(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"ord() expected a character, "
|
"ord() expected a character, "
|
||||||
"but string of length %d found",
|
"but string of length %d found",
|
||||||
size);
|
size);
|
||||||
|
@ -1539,7 +1539,7 @@ builtin_ord(PyObject *self, PyObject *args)
|
||||||
static char ord_doc[] =
|
static char ord_doc[] =
|
||||||
"ord(c) -> integer\n\
|
"ord(c) -> integer\n\
|
||||||
\n\
|
\n\
|
||||||
Return the integer ordinal of a one character string.";
|
Return the integer ordinal of a one-character string.";
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2014,9 +2014,9 @@ abstract_issubclass(PyObject *derived, PyObject *cls, int first)
|
||||||
if (first) {
|
if (first) {
|
||||||
bases = PyObject_GetAttr(cls, __bases__);
|
bases = PyObject_GetAttr(cls, __bases__);
|
||||||
if (bases == NULL || !PyTuple_Check(bases)) {
|
if (bases == NULL || !PyTuple_Check(bases)) {
|
||||||
Py_XDECREF(bases);
|
Py_XDECREF(bases);
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"arg 2 must be a class or type");
|
"issubclass() arg 2 must be a class");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_DECREF(bases);
|
Py_DECREF(bases);
|
||||||
|
@ -2029,7 +2029,7 @@ abstract_issubclass(PyObject *derived, PyObject *cls, int first)
|
||||||
if (bases == NULL || !PyTuple_Check(bases)) {
|
if (bases == NULL || !PyTuple_Check(bases)) {
|
||||||
Py_XDECREF(bases);
|
Py_XDECREF(bases);
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"arg 2 must be a class or type");
|
"issubclass() arg 1 must be a class");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2068,23 +2068,29 @@ builtin_isinstance(PyObject *self, PyObject *args)
|
||||||
retval = ((PyObject *)(inst->ob_type) == cls);
|
retval = ((PyObject *)(inst->ob_type) == cls);
|
||||||
}
|
}
|
||||||
else if (!PyInstance_Check(inst)) {
|
else if (!PyInstance_Check(inst)) {
|
||||||
if (__class__ == NULL) {
|
if (__class__ == NULL) {
|
||||||
__class__ = PyString_FromString("__class__");
|
__class__ = PyString_FromString("__class__");
|
||||||
if (__class__ == NULL)
|
if (__class__ == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
icls = PyObject_GetAttr(inst, __class__);
|
icls = PyObject_GetAttr(inst, __class__);
|
||||||
if (icls != NULL) {
|
if (icls != NULL) {
|
||||||
retval = abstract_issubclass( icls, cls, 1);
|
retval = abstract_issubclass(icls, cls, 1);
|
||||||
Py_DECREF(icls);
|
Py_DECREF(icls);
|
||||||
if (retval < 0)
|
if (retval < 0 &&
|
||||||
|
!PyErr_ExceptionMatches(PyExc_TypeError))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
PyErr_SetString(PyExc_TypeError,
|
retval = -1;
|
||||||
"arg 2 must be a class or type");
|
}
|
||||||
return NULL;
|
else
|
||||||
}
|
retval = -1;
|
||||||
|
|
||||||
|
if (retval < 0) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"isinstance() arg 2 must be a class or type");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyInt_FromLong(retval);
|
return PyInt_FromLong(retval);
|
||||||
}
|
}
|
||||||
|
@ -2108,7 +2114,7 @@ builtin_issubclass(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
if (!PyClass_Check(derived) || !PyClass_Check(cls)) {
|
if (!PyClass_Check(derived) || !PyClass_Check(cls)) {
|
||||||
retval = abstract_issubclass(derived, cls, 1);
|
retval = abstract_issubclass(derived, cls, 1);
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2261,7 +2267,7 @@ _PyBuiltin_Init(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyDict_SetItemString(dict, "Ellipsis", Py_Ellipsis) < 0)
|
if (PyDict_SetItemString(dict, "Ellipsis", Py_Ellipsis) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyDict_SetItemString(dict, "NotImplemented",
|
if (PyDict_SetItemString(dict, "NotImplemented",
|
||||||
Py_NotImplemented) < 0)
|
Py_NotImplemented) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
debug = PyInt_FromLong(Py_OptimizeFlag == 0);
|
debug = PyInt_FromLong(Py_OptimizeFlag == 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue