summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-09-12 10:27:50 (GMT)
committerGitHub <noreply@github.com>2021-09-12 10:27:50 (GMT)
commit92bf8691fb78f3484bf2daba836c416efedb1d8d (patch)
treef5e605dbb607ec58daa687300a5f59f99dd1aee4 /Objects/setobject.c
parent5277ffe12d492939544ff9c54a3aaf448b913fb3 (diff)
downloadcpython-92bf8691fb78f3484bf2daba836c416efedb1d8d.zip
cpython-92bf8691fb78f3484bf2daba836c416efedb1d8d.tar.gz
cpython-92bf8691fb78f3484bf2daba836c416efedb1d8d.tar.bz2
bpo-43413: Fix handling keyword arguments in subclasses of some buitin classes (GH-26456)
* Constructors of subclasses of some buitin classes (e.g. tuple, list, frozenset) no longer accept arbitrary keyword arguments. * Subclass of set can now define a __new__() method with additional keyword parameters without overriding also __init__().
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index caff85c..af521b2 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1009,7 +1009,9 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *iterable = NULL;
- if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset", kwds)) {
+ if ((type == &PyFrozenSet_Type ||
+ type->tp_init == PyFrozenSet_Type.tp_init) &&
+ !_PyArg_NoKeywords("frozenset", kwds)) {
return NULL;
}
@@ -1944,7 +1946,9 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
{
PyObject *iterable = NULL;
- if (!_PyArg_NoKeywords("set", kwds))
+ if ((Py_IS_TYPE(self, &PySet_Type) ||
+ Py_TYPE(self)->tp_new == PySet_Type.tp_new) &&
+ !_PyArg_NoKeywords("set", kwds))
return -1;
if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
return -1;