Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4078,7 +4078,7 @@ class E(D):
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__ = ()
Expand Down Expand Up @@ -5062,7 +5062,7 @@ class X:

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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Exception text when trying to delete attributes of types was clarified.
8 changes: 4 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,15 +1465,15 @@ static PyMemberDef type_members[] = {
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;
}
Expand Down
Loading