summaryrefslogtreecommitdiffstats
path: root/Objects
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
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')
-rw-r--r--Objects/clinic/codeobject.c.h5
-rw-r--r--Objects/clinic/enumobject.c.h5
-rw-r--r--Objects/clinic/floatobject.c.h5
-rw-r--r--Objects/clinic/listobject.c.h5
-rw-r--r--Objects/clinic/tupleobject.c.h5
-rw-r--r--Objects/setobject.c8
6 files changed, 21 insertions, 12 deletions
diff --git a/Objects/clinic/codeobject.c.h b/Objects/clinic/codeobject.c.h
index ac844b1..ee425f6 100644
--- a/Objects/clinic/codeobject.c.h
+++ b/Objects/clinic/codeobject.c.h
@@ -46,7 +46,8 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *freevars = NULL;
PyObject *cellvars = NULL;
- if ((type == &PyCode_Type) &&
+ if ((type == &PyCode_Type ||
+ type->tp_init == PyCode_Type.tp_init) &&
!_PyArg_NoKeywords("code", kwargs)) {
goto exit;
}
@@ -455,4 +456,4 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
exit:
return return_value;
}
-/*[clinic end generated code: output=18b9ddc86714e56e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9e8c4a19474ec520 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/enumobject.c.h b/Objects/clinic/enumobject.c.h
index 09d4c87..7513c95 100644
--- a/Objects/clinic/enumobject.c.h
+++ b/Objects/clinic/enumobject.c.h
@@ -64,7 +64,8 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
PyObject *seq;
- if ((type == &PyReversed_Type) &&
+ if ((type == &PyReversed_Type ||
+ type->tp_init == PyReversed_Type.tp_init) &&
!_PyArg_NoKeywords("reversed", kwargs)) {
goto exit;
}
@@ -77,4 +78,4 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=e18c3fefcf914ec7 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a3937b6b33499560 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index 5643f0e..88dc482 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -208,7 +208,8 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
PyObject *x = NULL;
- if ((type == &PyFloat_Type) &&
+ if ((type == &PyFloat_Type ||
+ type->tp_init == PyFloat_Type.tp_init) &&
!_PyArg_NoKeywords("float", kwargs)) {
goto exit;
}
@@ -387,4 +388,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=bb079c3e130e4ce6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=122a73f4c9d25806 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h
index 01e31d7..75ed9f9 100644
--- a/Objects/clinic/listobject.c.h
+++ b/Objects/clinic/listobject.c.h
@@ -299,7 +299,8 @@ list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
int return_value = -1;
PyObject *iterable = NULL;
- if (Py_IS_TYPE(self, &PyList_Type) &&
+ if ((Py_IS_TYPE(self, &PyList_Type) ||
+ Py_TYPE(self)->tp_new == PyList_Type.tp_new) &&
!_PyArg_NoKeywords("list", kwargs)) {
goto exit;
}
@@ -352,4 +353,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list___reversed___impl(self);
}
-/*[clinic end generated code: output=0063aad535edf62d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=acb2f87736311930 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h
index fe2fae4..f65e5fa 100644
--- a/Objects/clinic/tupleobject.c.h
+++ b/Objects/clinic/tupleobject.c.h
@@ -77,7 +77,8 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
PyObject *iterable = NULL;
- if ((type == &PyTuple_Type) &&
+ if ((type == &PyTuple_Type ||
+ type->tp_init == PyTuple_Type.tp_init) &&
!_PyArg_NoKeywords("tuple", kwargs)) {
goto exit;
}
@@ -111,4 +112,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
{
return tuple___getnewargs___impl(self);
}
-/*[clinic end generated code: output=56fab9b7368aba49 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=72cc0bc4f7358116 input=a9049054013a1b77]*/
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;