summaryrefslogtreecommitdiffstats
path: root/Modules
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 /Modules
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 'Modules')
-rw-r--r--Modules/_io/clinic/bufferedio.c.h5
-rw-r--r--Modules/_randommodule.c5
-rw-r--r--Modules/_sqlite/clinic/cursor.c.h5
-rw-r--r--Modules/_sqlite/clinic/row.c.h5
-rw-r--r--Modules/arraymodule.c4
-rw-r--r--Modules/clinic/_collectionsmodule.c.h5
-rw-r--r--Modules/clinic/_queuemodule.c.h8
-rw-r--r--Modules/clinic/_ssl.c.h11
-rw-r--r--Modules/clinic/itertoolsmodule.c.h29
-rw-r--r--Modules/clinic/selectmodule.c.h8
-rw-r--r--Modules/itertoolsmodule.c6
11 files changed, 58 insertions, 33 deletions
diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h
index 19543fd..2fd0232 100644
--- a/Modules/_io/clinic/bufferedio.c.h
+++ b/Modules/_io/clinic/bufferedio.c.h
@@ -553,7 +553,8 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *writer;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
- if (Py_IS_TYPE(self, &PyBufferedRWPair_Type) &&
+ if ((Py_IS_TYPE(self, &PyBufferedRWPair_Type) ||
+ Py_TYPE(self)->tp_new == PyBufferedRWPair_Type.tp_new) &&
!_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
goto exit;
}
@@ -637,4 +638,4 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=98ccf7610c0e82ba input=a9049054013a1b77]*/
+/*[clinic end generated code: output=79138a088729b5ee input=a9049054013a1b77]*/
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 7ad4299..65d41f4 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -523,8 +523,9 @@ random_init(RandomObject *self, PyObject *args, PyObject *kwds)
PyObject *arg = NULL;
_randomstate *state = _randomstate_type(Py_TYPE(self));
- if (Py_IS_TYPE(self, (PyTypeObject *)state->Random_Type) &&
- !_PyArg_NoKeywords("Random()", kwds)) {
+ if ((Py_IS_TYPE(self, (PyTypeObject *)state->Random_Type) ||
+ Py_TYPE(self)->tp_init == ((PyTypeObject*)state->Random_Type)->tp_init) &&
+ !_PyArg_NoKeywords("Random", kwds)) {
return -1;
}
diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h
index 07e1587..eb3e7ce 100644
--- a/Modules/_sqlite/clinic/cursor.c.h
+++ b/Modules/_sqlite/clinic/cursor.c.h
@@ -12,7 +12,8 @@ pysqlite_cursor_init(PyObject *self, PyObject *args, PyObject *kwargs)
int return_value = -1;
pysqlite_Connection *connection;
- if (Py_IS_TYPE(self, clinic_state()->CursorType) &&
+ if ((Py_IS_TYPE(self, clinic_state()->CursorType) ||
+ Py_TYPE(self)->tp_new == clinic_state()->CursorType->tp_new) &&
!_PyArg_NoKeywords("Cursor", kwargs)) {
goto exit;
}
@@ -299,4 +300,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyTypeObject *cls, PyObject *const
exit:
return return_value;
}
-/*[clinic end generated code: output=ace31a7481aa3f41 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3b5328c1619b7626 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/row.c.h b/Modules/_sqlite/clinic/row.c.h
index 310d62b..c936ef7 100644
--- a/Modules/_sqlite/clinic/row.c.h
+++ b/Modules/_sqlite/clinic/row.c.h
@@ -13,7 +13,8 @@ pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
pysqlite_Cursor *cursor;
PyObject *data;
- if ((type == clinic_state()->RowType) &&
+ if ((type == clinic_state()->RowType ||
+ type->tp_init == clinic_state()->RowType->tp_init) &&
!_PyArg_NoKeywords("Row", kwargs)) {
goto exit;
}
@@ -53,4 +54,4 @@ pysqlite_row_keys(pysqlite_Row *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_row_keys_impl(self);
}
-/*[clinic end generated code: output=0382771b4fc85f36 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9d54919dbb4ba5f1 input=a9049054013a1b77]*/
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 1d9d4cd..9a3203c 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2617,7 +2617,9 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *initial = NULL, *it = NULL;
const struct arraydescr *descr;
- if (type == state->ArrayType && !_PyArg_NoKeywords("array.array", kwds))
+ if ((type == state->ArrayType ||
+ type->tp_init == state->ArrayType->tp_init) &&
+ !_PyArg_NoKeywords("array.array", kwds))
return NULL;
if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial))
diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h
index 7e18aeb..2875b3c 100644
--- a/Modules/clinic/_collectionsmodule.c.h
+++ b/Modules/clinic/_collectionsmodule.c.h
@@ -43,7 +43,8 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
Py_ssize_t index;
PyObject *doc;
- if ((type == &tuplegetter_type) &&
+ if ((type == &tuplegetter_type ||
+ type->tp_init == tuplegetter_type.tp_init) &&
!_PyArg_NoKeywords("_tuplegetter", kwargs)) {
goto exit;
}
@@ -68,4 +69,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=947186d369f50f1e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3dfa12a35e655844 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_queuemodule.c.h b/Modules/clinic/_queuemodule.c.h
index 8741f7d..d952256 100644
--- a/Modules/clinic/_queuemodule.c.h
+++ b/Modules/clinic/_queuemodule.c.h
@@ -16,11 +16,13 @@ simplequeue_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
- if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) &&
+ if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType ||
+ type->tp_init == simplequeue_get_state_by_type(type)->SimpleQueueType->tp_init) &&
!_PyArg_NoPositional("SimpleQueue", args)) {
goto exit;
}
- if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) &&
+ if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType ||
+ type->tp_init == simplequeue_get_state_by_type(type)->SimpleQueueType->tp_init) &&
!_PyArg_NoKeywords("SimpleQueue", kwargs)) {
goto exit;
}
@@ -246,4 +248,4 @@ _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
exit:
return return_value;
}
-/*[clinic end generated code: output=ce56b46fac150909 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=96cc57168d72aab1 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h
index b59b129..67eaf3f 100644
--- a/Modules/clinic/_ssl.c.h
+++ b/Modules/clinic/_ssl.c.h
@@ -408,7 +408,8 @@ _ssl__SSLContext(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
int proto_version;
- if ((type == get_state_type(type)->PySSLContext_Type) &&
+ if ((type == get_state_type(type)->PySSLContext_Type ||
+ type->tp_init == get_state_type(type)->PySSLContext_Type->tp_init) &&
!_PyArg_NoKeywords("_SSLContext", kwargs)) {
goto exit;
}
@@ -884,11 +885,13 @@ _ssl_MemoryBIO(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
- if ((type == get_state_type(type)->PySSLMemoryBIO_Type) &&
+ if ((type == get_state_type(type)->PySSLMemoryBIO_Type ||
+ type->tp_init == get_state_type(type)->PySSLMemoryBIO_Type->tp_init) &&
!_PyArg_NoPositional("MemoryBIO", args)) {
goto exit;
}
- if ((type == get_state_type(type)->PySSLMemoryBIO_Type) &&
+ if ((type == get_state_type(type)->PySSLMemoryBIO_Type ||
+ type->tp_init == get_state_type(type)->PySSLMemoryBIO_Type->tp_init) &&
!_PyArg_NoKeywords("MemoryBIO", kwargs)) {
goto exit;
}
@@ -1358,4 +1361,4 @@ exit:
#ifndef _SSL_ENUM_CRLS_METHODDEF
#define _SSL_ENUM_CRLS_METHODDEF
#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
-/*[clinic end generated code: output=5a7d7bf5cf8ee092 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=cd2a53c26eda295e input=a9049054013a1b77]*/
diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h
index 82729ee..7f5abe6 100644
--- a/Modules/clinic/itertoolsmodule.c.h
+++ b/Modules/clinic/itertoolsmodule.c.h
@@ -19,7 +19,8 @@ pairwise_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
PyObject *iterable;
- if ((type == &pairwise_type) &&
+ if ((type == &pairwise_type ||
+ type->tp_init == pairwise_type.tp_init) &&
!_PyArg_NoKeywords("pairwise", kwargs)) {
goto exit;
}
@@ -89,7 +90,8 @@ itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *parent;
PyObject *tgtkey;
- if ((type == &_grouper_type) &&
+ if ((type == &_grouper_type ||
+ type->tp_init == _grouper_type.tp_init) &&
!_PyArg_NoKeywords("_grouper", kwargs)) {
goto exit;
}
@@ -126,7 +128,8 @@ itertools_teedataobject(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *values;
PyObject *next;
- if ((type == &teedataobject_type) &&
+ if ((type == &teedataobject_type ||
+ type->tp_init == teedataobject_type.tp_init) &&
!_PyArg_NoKeywords("teedataobject", kwargs)) {
goto exit;
}
@@ -161,7 +164,8 @@ itertools__tee(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
PyObject *iterable;
- if ((type == &tee_type) &&
+ if ((type == &tee_type ||
+ type->tp_init == tee_type.tp_init) &&
!_PyArg_NoKeywords("_tee", kwargs)) {
goto exit;
}
@@ -235,7 +239,8 @@ itertools_cycle(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *return_value = NULL;
PyObject *iterable;
- if ((type == &cycle_type) &&
+ if ((type == &cycle_type ||
+ type->tp_init == cycle_type.tp_init) &&
!_PyArg_NoKeywords("cycle", kwargs)) {
goto exit;
}
@@ -267,7 +272,8 @@ itertools_dropwhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *func;
PyObject *seq;
- if ((type == &dropwhile_type) &&
+ if ((type == &dropwhile_type ||
+ type->tp_init == dropwhile_type.tp_init) &&
!_PyArg_NoKeywords("dropwhile", kwargs)) {
goto exit;
}
@@ -298,7 +304,8 @@ itertools_takewhile(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *func;
PyObject *seq;
- if ((type == &takewhile_type) &&
+ if ((type == &takewhile_type ||
+ type->tp_init == takewhile_type.tp_init) &&
!_PyArg_NoKeywords("takewhile", kwargs)) {
goto exit;
}
@@ -329,7 +336,8 @@ itertools_starmap(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *func;
PyObject *seq;
- if ((type == &starmap_type) &&
+ if ((type == &starmap_type ||
+ type->tp_init == starmap_type.tp_init) &&
!_PyArg_NoKeywords("starmap", kwargs)) {
goto exit;
}
@@ -593,7 +601,8 @@ itertools_filterfalse(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *func;
PyObject *seq;
- if ((type == &filterfalse_type) &&
+ if ((type == &filterfalse_type ||
+ type->tp_init == filterfalse_type.tp_init) &&
!_PyArg_NoKeywords("filterfalse", kwargs)) {
goto exit;
}
@@ -658,4 +667,4 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=889c4afc3b13574f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5364de2e143609b9 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/selectmodule.c.h b/Modules/clinic/selectmodule.c.h
index d7095df..a1695f2 100644
--- a/Modules/clinic/selectmodule.c.h
+++ b/Modules/clinic/selectmodule.c.h
@@ -933,11 +933,13 @@ select_kqueue(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
- if ((type == _selectstate_by_type(type)->kqueue_queue_Type) &&
+ if ((type == _selectstate_by_type(type)->kqueue_queue_Type ||
+ type->tp_init == _selectstate_by_type(type)->kqueue_queue_Type->tp_init) &&
!_PyArg_NoPositional("kqueue", args)) {
goto exit;
}
- if ((type == _selectstate_by_type(type)->kqueue_queue_Type) &&
+ if ((type == _selectstate_by_type(type)->kqueue_queue_Type ||
+ type->tp_init == _selectstate_by_type(type)->kqueue_queue_Type->tp_init) &&
!_PyArg_NoKeywords("kqueue", kwargs)) {
goto exit;
}
@@ -1179,4 +1181,4 @@ exit:
#ifndef SELECT_KQUEUE_CONTROL_METHODDEF
#define SELECT_KQUEUE_CONTROL_METHODDEF
#endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
-/*[clinic end generated code: output=cd2062a787e13b35 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ed1e5a658863244c input=a9049054013a1b77]*/
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 643f47b..ec0aa76 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1614,7 +1614,8 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_ssize_t numargs;
isliceobject *lz;
- if (type == &islice_type && !_PyArg_NoKeywords("islice", kwds))
+ if ((type == &islice_type || type->tp_init == islice_type.tp_init) &&
+ !_PyArg_NoKeywords("islice", kwds))
return NULL;
if (!PyArg_UnpackTuple(args, "islice", 2, 4, &seq, &a1, &a2, &a3))
@@ -2021,7 +2022,8 @@ chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *source;
- if (type == &chain_type && !_PyArg_NoKeywords("chain", kwds))
+ if ((type == &chain_type || type->tp_init == chain_type.tp_init) &&
+ !_PyArg_NoKeywords("chain", kwds))
return NULL;
source = PyObject_GetIter(args);