@@ -1065,6 +1065,8 @@ set_union(PySetObject *so, PyObject *other)
10651065 result = (PySetObject * )set_copy (so );
10661066 if (result == NULL )
10671067 return NULL ;
1068+ if ((PyObject * )so == other )
1069+ return (PyObject * )result ;
10681070 if (set_update_internal (result , other ) == -1 ) {
10691071 Py_DECREF (result );
10701072 return NULL ;
@@ -1106,10 +1108,8 @@ set_intersection(PySetObject *so, PyObject *other)
11061108 PySetObject * result ;
11071109 PyObject * key , * it , * tmp ;
11081110
1109- if ((PyObject * )so == other ) {
1110- Py_INCREF (other );
1111- return other ;
1112- }
1111+ if ((PyObject * )so == other )
1112+ return set_copy (so );
11131113
11141114 result = (PySetObject * )make_new_set (so -> ob_type , NULL );
11151115 if (result == NULL )
@@ -2062,13 +2062,14 @@ test_c_api(PySetObject *so)
20622062 Py_DECREF (f );
20632063
20642064 /* Raise KeyError when popping from an empty set */
2065- set_clear_internal (so );
2065+ assert (PyNumber_InPlaceSubtract (ob , ob ) == ob );
2066+ Py_DECREF (ob );
20662067 assert (PySet_GET_SIZE (ob ) == 0 );
20672068 assertRaises (PySet_Pop (ob ) == NULL , PyExc_KeyError );
20682069
2069- /* Restore the set from the copy and use the abstract API */
2070- assert (PyObject_CallMethod (ob , "update" , "O" , dup ) == Py_None );
2071- Py_DECREF (Py_None );
2070+ /* Restore the set from the copy using the PyNumber API */
2071+ assert (PyNumber_InPlaceOr (ob , dup ) == ob );
2072+ Py_DECREF (ob );
20722073
20732074 /* Verify constructors accept NULL arguments */
20742075 f = PySet_New (NULL );
0 commit comments