summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2000-12-04 15:42:11 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2000-12-04 15:42:11 (GMT)
commitcc343caf419c7f29ececd67b6119d1b7c9a6b6be (patch)
treebf8e810b8ed64e0fd6254ebd9f2c1eacad2d8e35 /Python
parent24342d96c51e852453d5844d7a9fbc05a7d2f50d (diff)
downloadcpython-cc343caf419c7f29ececd67b6119d1b7c9a6b6be.zip
cpython-cc343caf419c7f29ececd67b6119d1b7c9a6b6be.tar.gz
cpython-cc343caf419c7f29ececd67b6119d1b7c9a6b6be.tar.bz2
Make isinstance() more permissive in what types of arguments it
accepts. Clarify exception messages for isinstance() and issubclass(). Closes bug #124106.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 7c8cf18..fa560f7 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1995,7 +1995,7 @@ Without arguments, equivalent to locals().\n\
With an argument, equivalent to object.__dict__.";
static int
-abstract_issubclass(PyObject *derived, PyObject *cls, char *err, int first)
+abstract_issubclass(PyObject *derived, PyObject *cls, int first)
{
static PyObject *__bases__ = NULL;
PyObject *bases;
@@ -2012,7 +2012,8 @@ abstract_issubclass(PyObject *derived, PyObject *cls, char *err, int first)
bases = PyObject_GetAttr(cls, __bases__);
if (bases == NULL || !PyTuple_Check(bases)) {
Py_XDECREF(bases);
- PyErr_SetString(PyExc_TypeError, err);
+ PyErr_SetString(PyExc_TypeError,
+ "arg 2 must be a class or type");
return -1;
}
Py_DECREF(bases);
@@ -2024,14 +2025,14 @@ abstract_issubclass(PyObject *derived, PyObject *cls, char *err, int first)
bases = PyObject_GetAttr(derived, __bases__);
if (bases == NULL || !PyTuple_Check(bases)) {
Py_XDECREF(bases);
- PyErr_SetString(PyExc_TypeError, err);
+ PyErr_SetString(PyExc_TypeError,
+ "arg 2 must be a class or type");
return -1;
}
n = PyTuple_GET_SIZE(bases);
for (i = 0; i < n; i++) {
- r = abstract_issubclass(PyTuple_GET_ITEM(bases, i),
- cls, err, 0);
+ r = abstract_issubclass(PyTuple_GET_ITEM(bases, i), cls, 0);
if (r != 0)
break;
}
@@ -2071,25 +2072,17 @@ builtin_isinstance(PyObject *self, PyObject *args)
}
icls = PyObject_GetAttr(inst, __class__);
if (icls != NULL) {
- retval = abstract_issubclass(
- icls, cls,
- "isinstance() arg 2 must be a class",
- 1);
+ retval = abstract_issubclass( icls, cls, 1);
Py_DECREF(icls);
if (retval < 0)
return NULL;
}
else {
PyErr_SetString(PyExc_TypeError,
- "isinstance() arg 2 must be a class");
+ "arg 2 must be a class or type");
return NULL;
}
}
- else {
- PyErr_SetString(PyExc_TypeError,
- "isinstance() arg 2 must be a class");
- return NULL;
- }
return PyInt_FromLong(retval);
}
@@ -2111,8 +2104,7 @@ builtin_issubclass(PyObject *self, PyObject *args)
return NULL;
if (!PyClass_Check(derived) || !PyClass_Check(cls)) {
- retval = abstract_issubclass(
- derived, cls, "arguments must be classes", 1);
+ retval = abstract_issubclass(derived, cls, 1);
if (retval < 0)
return NULL;
}