]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43413: Revert changes in set.__init__ (GH-28403)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 26 Dec 2021 11:27:01 +0000 (13:27 +0200)
committerGitHub <noreply@github.com>
Sun, 26 Dec 2021 11:27:01 +0000 (13:27 +0200)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/test/test_set.py
Misc/NEWS.d/3.11.0a1.rst
Misc/NEWS.d/next/Core and Builtins/2021-05-30-16-37-47.bpo-43413.vYFPPC1.rst [new file with mode: 0644]
Objects/setobject.c

index 65fda9e469bccccc61d0244371cbf5c27f91c849..77f3da40c063abaf4419eedfc5ba5a2d5a971658 100644 (file)
@@ -667,10 +667,13 @@ class TestSetSubclass(TestSet):
                 self = super().__new__(cls, arg)
                 self.newarg = newarg
                 return self
-        u = subclass_with_new([1, 2], newarg=3)
+        u = subclass_with_new([1, 2])
         self.assertIs(type(u), subclass_with_new)
         self.assertEqual(set(u), {1, 2})
-        self.assertEqual(u.newarg, 3)
+        self.assertIsNone(u.newarg)
+        # disallow kwargs in __new__ only (https://bugs.python.org/issue43413#msg402000)
+        with self.assertRaises(TypeError):
+            subclass_with_new([1, 2], newarg=3)
 
 
 class TestFrozenSet(TestJointOps, unittest.TestCase):
index 28b81b75266fc262f235c4e48f9079b7a68914b6..fa30c693c34c1e0926dc2191dbd47e3cb4dd5ee6 100644 (file)
@@ -1140,7 +1140,7 @@ blocks. Patch by Pablo Galindo.
 
 Constructors of subclasses of some builtin classes (e.g. :class:`tuple`,
 :class:`list`, :class:`frozenset`) no longer accept arbitrary keyword
-arguments. Subclass of :class:`set` can now define a ``__new__()`` method
+arguments. [reverted in 3.11a4] Subclass of :class:`set` can now define a ``__new__()`` method
 with additional keyword parameters without overriding also ``__init__()``.
 
 ..
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-05-30-16-37-47.bpo-43413.vYFPPC1.rst b/Misc/NEWS.d/next/Core and Builtins/2021-05-30-16-37-47.bpo-43413.vYFPPC1.rst
new file mode 100644 (file)
index 0000000..cf879ec
--- /dev/null
@@ -0,0 +1 @@
+Revert changes in ``set.__init__``. Subclass of :class:`set` needs to define a ``__init__()`` method if it defines a ``__new__()`` method with additional keyword parameters.
index 0be067857d69466cc9158553d0738c3dc979c53a..6e110ef196c828f3319fcf84d8b0f628b6d33902 100644 (file)
@@ -1946,9 +1946,7 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
 {
     PyObject *iterable = NULL;
 
-     if ((Py_IS_TYPE(self, &PySet_Type) ||
-          Py_TYPE(self)->tp_new == PySet_Type.tp_new) &&
-         !_PyArg_NoKeywords("set", kwds))
+     if (!_PyArg_NoKeywords("set", kwds))
         return -1;
     if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
         return -1;