class X(int(), C):
pass
+ @unittest.skipIf(_testcapi is None, 'need the _testcapi module')
+ def test_type_with_null_new_metaclass(self):
+ metaclass = _testcapi.HeapCTypeMetaclassNullNew
+ base = _testcapi.pytype_fromspec_meta(metaclass)
+
+ # Exercise type_new's metaclass selection path, not a direct call.
+ with self.assertRaisesRegex(TypeError, r"cannot create '.*' instances"):
+ type("Derived", (base,), {})
+
def test_module_subclasses(self):
# Testing Python subclass of module...
log = []
if (winner != ctx->metatype) {
if (winner->tp_new != type_new) {
+ /* Check if tp_new is NULL (cannot instantiate this type) */
+ if (winner->tp_new == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "cannot create '%.400s' instances",
+ winner->tp_name);
+ return -1;
+ }
/* Pass it to the winner */
*type = winner->tp_new(winner, ctx->args, ctx->kwds);
if (*type == NULL) {