diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index bdcd1254b3..678d5906b6 100644
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -40,6 +40,10 @@ def test_bad_constructor(self):
self.assertRaises(TypeError, array.array, 'xx')
self.assertRaises(ValueError, array.array, 'x')
+ # See bpo-43916
+ with self.assertRaises(TypeError):
+ type(iter(array.array('I')))()
+
def test_empty(self):
# Exercise code for handling zero-length arrays
a = array.array('B')
diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py
index edfd860fd5..2acf387d00 100644
--- a/Lib/test/test_unicodedata.py
+++ b/Lib/test/test_unicodedata.py
@@ -309,6 +309,10 @@ def test_linebreak_7643(self):
self.assertEqual(len(lines), 1,
r"\u%.4x should not be a linebreak" % i)
+ def test_no_uninit_new(self):
+ # See bpo-43916
+ self.assertRaises(TypeError, unicodedata.UCD)
+
class NormalizationTest(unittest.TestCase):
@staticmethod
def check_version(testfile):
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 97772a04d0..40cc8e7461 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -499,6 +499,7 @@ _dbm_exec(PyObject *module)
if (state->dbm_type == NULL) {
return -1;
}
+ state->dbm_type->tp_new = 0; // See bpo-43916
state->dbm_error = PyErr_NewException("_dbm.error", PyExc_OSError, NULL);
if (state->dbm_error == NULL) {
return -1;
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index eea542e18c..c70e094fc9 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -1451,6 +1451,7 @@ _functools_exec(PyObject *module)
if (state->keyobject_type == NULL) {
return -1;
}
+ state->keyobject_type->tp_new = 0; // See bpo-43916
if (PyModule_AddType(module, state->keyobject_type) < 0) {
return -1;
}
@@ -1460,6 +1461,7 @@ _functools_exec(PyObject *module)
if (state->lru_list_elem_type == NULL) {
return -1;
}
+ state->lru_list_elem_type->tp_new = 0; // See bpo-43916
if (PyModule_AddType(module, state->lru_list_elem_type) < 0) {
return -1;
}
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index 9e843acbaa..2041674c12 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -702,6 +702,7 @@ _gdbm_exec(PyObject *module)
if (state->gdbm_type == NULL) {
return -1;
}
+ state->gdbm_type->tp_new = 0; // See bpo-43916
state->gdbm_error = PyErr_NewException("_gdbm.error", PyExc_OSError, NULL);
if (state->gdbm_error == NULL) {
return -1;
diff --git a/Modules/_sre.c b/Modules/_sre.c
index d4bfff6e84..508bbc9fb1 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -2856,6 +2856,11 @@ sre_exec(PyObject *m)
CREATE_TYPE(m, state->Match_Type, &match_spec);
CREATE_TYPE(m, state->Scanner_Type, &scanner_spec);
+ // See bpo-43916
+ state->Pattern_Type->tp_new = 0;
+ state->Match_Type->tp_new = 0;
+ state->Scanner_Type->tp_new = 0;
+
if (PyModule_AddIntConstant(m, "MAGIC", SRE_MAGIC) < 0) {
goto error;
}
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 7feb0b8a1f..a84008ac59 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1580,6 +1580,7 @@ thread_module_exec(PyObject *module)
if (state->lock_type == NULL) {
return -1;
}
+ state->lock_type->tp_new = 0; // See bpo-43916
if (PyDict_SetItemString(d, "LockType", (PyObject *)state->lock_type) < 0) {
return -1;
}
@@ -1600,6 +1601,7 @@ thread_module_exec(PyObject *module)
if (state->local_dummy_type == NULL) {
return -1;
}
+ state->local_dummy_type->tp_new = 0; // See bpo-43916
// Local
state->local_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, &local_type_spec, NULL);
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 9d5a45adac..0df4d569fd 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -1931,6 +1931,7 @@ static int winapi_exec(PyObject *m)
if (st->overlapped_type == NULL) {
return -1;
}
+ st->overlapped_type->tp_new = 0; // See bpo-43916
if (PyModule_AddType(m, st->overlapped_type) < 0) {
return -1;
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index f532678952..d57418e81f 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -3040,6 +3040,7 @@ array_modexec(PyObject *m)
CREATE_TYPE(m, state->ArrayType, &array_spec);
CREATE_TYPE(m, state->ArrayIterType, &arrayiter_spec);
+ state->ArrayIterType->tp_new = 0; // See bpo-43916
Py_SET_TYPE(state->ArrayIterType, &PyType_Type);
Py_INCREF((PyObject *)state->ArrayType);
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 5070c983d4..7623dd8498 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -2012,6 +2012,7 @@ _multibytecodec_exec(PyObject *mod)
{
_multibytecodec_state *state = _multibytecodec_get_state(mod);
CREATE_TYPE(mod, state->multibytecodec_type, &multibytecodec_spec);
+ state->multibytecodec_type->tp_new = 0; // See bpo-43916
CREATE_TYPE(mod, state->encoder_type, &encoder_spec);
CREATE_TYPE(mod, state->decoder_type, &decoder_spec);
CREATE_TYPE(mod, state->reader_type, &reader_spec);
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index ecd210e4ba..8e8c23bd18 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -15730,12 +15730,14 @@ posixmodule_exec(PyObject *m)
if (ScandirIteratorType == NULL) {
return -1;
}
+ ScandirIteratorType->tp_new = 0; // See bpo-43916
state->ScandirIteratorType = ScandirIteratorType;
PyObject *DirEntryType = PyType_FromModuleAndSpec(m, &DirEntryType_spec, NULL);
if (DirEntryType == NULL) {
return -1;
}
+ DirEntryType->tp_new = 0; // See bpo-43916
Py_INCREF(DirEntryType);
PyModule_AddObject(m, "DirEntry", DirEntryType);
state->DirEntryType = DirEntryType;
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index a13d340a3e..e0ae4d54f0 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1862,6 +1862,7 @@ pyexpat_exec(PyObject *mod)
if (state->xml_parse_type == NULL) {
return -1;
}
+ state->xml_parse_type->tp_new = 0; // See bpo-43916
if (init_handler_descrs(state) < 0) {
return -1;
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index aebae7da57..476662c739 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -1478,6 +1478,7 @@ unicodedata_exec(PyObject *module)
if (ucd_type == NULL) {
return -1;
}
+ ucd_type->tp_new = 0; // See bpo-43916
if (PyModule_AddType(module, ucd_type) < 0) {
Py_DECREF(ucd_type);
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index a537087d19..0ef412d744 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -1407,12 +1407,14 @@ zlib_exec(PyObject *mod)
if (state->Comptype == NULL) {
return -1;
}
+ state->Comptype->tp_new = 0; // See bpo-43916
state->Decomptype = (PyTypeObject *)PyType_FromModuleAndSpec(
mod, &Decomptype_spec, NULL);
if (state->Decomptype == NULL) {
return -1;
}
+ state->Decomptype->tp_new = 0; // See bpo-43916
state->ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
if (state->ZlibError == NULL) {