summaryrefslogtreecommitdiff
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-08-17 12:27:17 +0000
committerRaymond Hettinger <python@rcn.com>2005-08-17 12:27:17 +0000
commit1647020db64a56a674eb9d582c8bc5bfffc8a5f8 (patch)
tree31e85ea80bb80f6fa74cb5a6f139a5384a7ad0d3 /Objects/setobject.c
parente1414455848184cb0a8d2d7fc0e9bd0ee71522ad (diff)
downloadcpython-1647020db64a56a674eb9d582c8bc5bfffc8a5f8.tar.gz
Add shortcuts for a|a and a&a.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 9cf989cb2f..9a54aed876 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1065,6 +1065,8 @@ set_union(PySetObject *so, PyObject *other)
result = (PySetObject *)set_copy(so);
if (result == NULL)
return NULL;
+ if ((PyObject *)so == other)
+ return (PyObject *)result;
if (set_update_internal(result, other) == -1) {
Py_DECREF(result);
return NULL;
@@ -1106,10 +1108,8 @@ set_intersection(PySetObject *so, PyObject *other)
PySetObject *result;
PyObject *key, *it, *tmp;
- if ((PyObject *)so == other) {
- Py_INCREF(other);
- return other;
- }
+ if ((PyObject *)so == other)
+ return set_copy(so);
result = (PySetObject *)make_new_set(so->ob_type, NULL);
if (result == NULL)
@@ -2062,13 +2062,14 @@ test_c_api(PySetObject *so)
Py_DECREF(f);
/* Raise KeyError when popping from an empty set */
- set_clear_internal(so);
+ assert(PyNumber_InPlaceSubtract(ob, ob) == ob);
+ Py_DECREF(ob);
assert(PySet_GET_SIZE(ob) == 0);
assertRaises(PySet_Pop(ob) == NULL, PyExc_KeyError);
- /* Restore the set from the copy and use the abstract API */
- assert(PyObject_CallMethod(ob, "update", "O", dup) == Py_None);
- Py_DECREF(Py_None);
+ /* Restore the set from the copy using the PyNumber API */
+ assert(PyNumber_InPlaceOr(ob, dup) == ob);
+ Py_DECREF(ob);
/* Verify constructors accept NULL arguments */
f = PySet_New(NULL);