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__().
This commit is contained in:
Serhiy Storchaka 2021-09-12 13:27:50 +03:00 committed by GitHub
parent 5277ffe12d
commit 92bf8691fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 285 additions and 67 deletions

View file

@ -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))