[Python-checkins] [3.7] bpo-37219: Remove erroneous optimization for differencing an empty set (GH-13965) (GH-13968)
Raymond Hettinger
webhook-mailer at python.org
Tue Jun 11 05:01:28 EDT 2019
https://github.com/python/cpython/commit/1b615b2f035d207941e44259a92ed0bdcc56ac45
commit: 1b615b2f035d207941e44259a92ed0bdcc56ac45
branch: 3.7
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-11T02:01:06-07:00
summary:
[3.7] bpo-37219: Remove erroneous optimization for differencing an empty set (GH-13965) (GH-13968)
files:
A Misc/NEWS.d/next/Core and Builtins/2019-06-11-01-37-34.bpo-37219.jPSufq.rst
M Lib/test/test_set.py
M Objects/setobject.c
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index bb1081f034fe..e4766ab190be 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -895,6 +895,12 @@ def test_pickling(self):
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-11-01-37-34.bpo-37219.jPSufq.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-11-01-37-34.bpo-37219.jPSufq.rst
new file mode 100644
index 000000000000..ef8f52dce678
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-11-01-37-34.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 357e48ca3ce0..1e4781fe11ee 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1478,10 +1478,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);
@@ -1556,10 +1552,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);
- }
-
if (PyAnySet_Check(other)) {
other_size = PySet_GET_SIZE(other);
}
More information about the Python-checkins
mailing list