summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-11-16 11:44:54 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-11-16 11:44:54 (GMT)
commit7d99f09f89002d9afbf00befd7b2d78f4f9f17d8 (patch)
tree33150227e0381dea3bd9712c15e56ec0eaf19601 /Objects/setobject.c
parent4a1f593df5d4733831a1c4f03ca40c701433c43d (diff)
downloadcpython-7d99f09f89002d9afbf00befd7b2d78f4f9f17d8.zip
cpython-7d99f09f89002d9afbf00befd7b2d78f4f9f17d8.tar.gz
cpython-7d99f09f89002d9afbf00befd7b2d78f4f9f17d8.tar.bz2
Issue #1721812: Binary operations and copy operations on set/frozenset
subclasses need to return the base type, not the subclass itself.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index d24e1af..d08ff5f 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1017,6 +1017,18 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
return (PyObject *)so;
}
+static PyObject *
+make_new_set_basetype(PyTypeObject *type, PyObject *iterable)
+{
+ if (type != &PySet_Type && type != &PyFrozenSet_Type) {
+ if (PyType_IsSubtype(type, &PySet_Type))
+ type = &PySet_Type;
+ else
+ type = &PyFrozenSet_Type;
+ }
+ return make_new_set(type, iterable);
+}
+
/* The empty frozenset is a singleton */
static PyObject *emptyfrozenset = NULL;
@@ -1129,7 +1141,7 @@ set_swap_bodies(PySetObject *a, PySetObject *b)
static PyObject *
set_copy(PySetObject *so)
{
- return make_new_set(Py_TYPE(so), (PyObject *)so);
+ return make_new_set_basetype(Py_TYPE(so), (PyObject *)so);
}
static PyObject *
@@ -1225,7 +1237,7 @@ set_intersection(PySetObject *so, PyObject *other)
if ((PyObject *)so == other)
return set_copy(so);
- result = (PySetObject *)make_new_set(Py_TYPE(so), NULL);
+ result = (PySetObject *)make_new_set_basetype(Py_TYPE(so), NULL);
if (result == NULL)
return NULL;
@@ -1520,7 +1532,7 @@ set_difference(PySetObject *so, PyObject *other)
return NULL;
}
- result = make_new_set(Py_TYPE(so), NULL);
+ result = make_new_set_basetype(Py_TYPE(so), NULL);
if (result == NULL)
return NULL;
@@ -1641,7 +1653,7 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other)
Py_INCREF(other);
otherset = (PySetObject *)other;
} else {
- otherset = (PySetObject *)make_new_set(Py_TYPE(so), other);
+ otherset = (PySetObject *)make_new_set_basetype(Py_TYPE(so), other);
if (otherset == NULL)
return NULL;
}
@@ -1672,7 +1684,7 @@ set_symmetric_difference(PySetObject *so, PyObject *other)
PyObject *rv;
PySetObject *otherset;
- otherset = (PySetObject *)make_new_set(Py_TYPE(so), other);
+ otherset = (PySetObject *)make_new_set_basetype(Py_TYPE(so), other);
if (otherset == NULL)
return NULL;
rv = set_symmetric_difference_update(otherset, (PyObject *)so);