From 92bf8691fb78f3484bf2daba836c416efedb1d8d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 12 Sep 2021 13:27:50 +0300 Subject: 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__(). --- Python/bltinmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 73541835d6c..76c9f87fdf1 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -507,7 +507,8 @@ filter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *it; filterobject *lz; - if (type == &PyFilter_Type && !_PyArg_NoKeywords("filter", kwds)) + if ((type == &PyFilter_Type || type->tp_init == PyFilter_Type.tp_init) && + !_PyArg_NoKeywords("filter", kwds)) return NULL; if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq)) @@ -1218,7 +1219,8 @@ map_new(PyTypeObject *type, PyObject *args, PyObject *kwds) mapobject *lz; Py_ssize_t numargs, i; - if (type == &PyMap_Type && !_PyArg_NoKeywords("map", kwds)) + if ((type == &PyMap_Type || type->tp_init == PyMap_Type.tp_init) && + !_PyArg_NoKeywords("map", kwds)) return NULL; numargs = PyTuple_Size(args); -- cgit v1.2.3