Skip to content

Commit af4f903

Browse files
authored
Fix error messages for deleting/setting type attributes
Deleting is always an error and doesn't depend on mutability. Setting is tested after deleting.
1 parent b48a3db commit af4f903

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Objects/typeobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,15 +1125,16 @@ static PyMemberDef type_members[] = {
11251125
static int
11261126
check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *name)
11271127
{
1128-
if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {
1128+
1129+
if (!value) {
11291130
PyErr_Format(PyExc_TypeError,
1130-
"cannot set '%s' attribute of immutable type '%s'",
1131+
"cannot delete '%s' attribute of type '%s'",
11311132
name, type->tp_name);
11321133
return 0;
11331134
}
1134-
if (!value) {
1135+
if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {
11351136
PyErr_Format(PyExc_TypeError,
1136-
"cannot delete '%s' attribute of immutable type '%s'",
1137+
"cannot set '%s' attribute of immutable type '%s'",
11371138
name, type->tp_name);
11381139
return 0;
11391140
}

0 commit comments

Comments
 (0)