self.assertEqual(C2.__subclasses__(), [D])
with self.assertRaisesRegex(TypeError,
- "cannot delete '__bases__' attribute of immutable type"):
+ "cannot delete '__bases__' attribute of type 'D'"):
del D.__bases__
with self.assertRaisesRegex(TypeError, 'can only assign non-empty tuple'):
D.__bases__ = ()
with self.assertRaises(TypeError) as cm:
type(X).__dict__["__doc__"].__delete__(X)
- self.assertIn("cannot delete '__doc__' attribute of immutable type 'X'", str(cm.exception))
+ self.assertIn("cannot delete '__doc__' attribute of type 'X'", str(cm.exception))
self.assertEqual(X.__doc__, "banana")
def test_qualname(self):
static int
check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *name)
{
- if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {
+ if (!value) {
PyErr_Format(PyExc_TypeError,
- "cannot set '%s' attribute of immutable type '%s'",
+ "cannot delete '%s' attribute of type '%s'",
name, type->tp_name);
return 0;
}
- if (!value) {
+ if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {
PyErr_Format(PyExc_TypeError,
- "cannot delete '%s' attribute of immutable type '%s'",
+ "cannot set '%s' attribute of immutable type '%s'",
name, type->tp_name);
return 0;
}