summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-06-11 08:15:24 (GMT)
committerGitHub <noreply@github.com>2019-06-11 08:15:24 (GMT)
commit1f11cf9521114447b3e32e2ac88f075ffaa37555 (patch)
tree5ae0cb114a30299b34a32db228d13017bf5e3bf5
parent408a2ef1aceff1f4270c44552fa39ef93d9283e3 (diff)
downloadcpython-1f11cf9521114447b3e32e2ac88f075ffaa37555.zip
cpython-1f11cf9521114447b3e32e2ac88f075ffaa37555.tar.gz
cpython-1f11cf9521114447b3e32e2ac88f075ffaa37555.tar.bz2
bpo-37219: Remove erroneous optimization for differencing an empty set (GH-13965)
-rw-r--r--Lib/test/test_set.py6
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2019-06-10-23-18-31.bpo-37219.jPSufq.rst1
-rw-r--r--Objects/setobject.c8
3 files changed, 7 insertions, 8 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index bb1081f..e4766ab 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -895,6 +895,12 @@ class TestBasicOps:
self.assertEqual(self.set, copy,
"%s != %s" % (self.set, copy))
+ def test_issue_37219(self):
+ with self.assertRaises(TypeError):
+ set().difference(123)
+ with self.assertRaises(TypeError):
+ set().difference_update(123)
+
#------------------------------------------------------------------------------
class TestBasicOpsEmpty(TestBasicOps, unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-10-23-18-31.bpo-37219.jPSufq.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-10-23-18-31.bpo-37219.jPSufq.rst
new file mode 100644
index 0000000..ef8f52d
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-10-23-18-31.bpo-37219.jPSufq.rst
@@ -0,0 +1 @@
+Remove errorneous optimization for empty set differences.
diff --git a/Objects/setobject.c b/Objects/setobject.c
index bd03160..8cd95ba 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1456,10 +1456,6 @@ PyDoc_STRVAR(isdisjoint_doc,
static int
set_difference_update_internal(PySetObject *so, PyObject *other)
{
- if (PySet_GET_SIZE(so) == 0) {
- return 0;
- }
-
if ((PyObject *)so == other)
return set_clear_internal(so);
@@ -1534,10 +1530,6 @@ set_difference(PySetObject *so, PyObject *other)
Py_ssize_t pos = 0, other_size;
int rv;
- if (PySet_GET_SIZE(so) == 0) {
- return set_copy(so, NULL);
- }
-
if (PyAnySet_Check(other)) {
other_size = PySet_GET_SIZE(other);
}