New GitHub issue #119494 from da-woods:<br>
<hr>
<pre>
# Bug report
### Bug description:
This is a fairly minor bug - the behaviour the interpreter disallows looks correct but the error messages look unhelpful.
```python
>>> class C:
... pass
...
>>> C.__name__
'C'
>>> C.__name__ = 'D'
>>> C.__name__
'D'
>>> del C.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot delete '__name__' attribute of immutable type 'D'
```
You can reassign the name fine and this works (because the type isn't immutable). However if you try to delete the name then it tells you that it's because the *type* is immutable.
In 3.9 this changes and it just reports:
```
>>> del C.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't delete C.__name__
```
------------------------
Relatedly, if you try to delete the name of an immutable type:
```
>>> del dict.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot set '__name__' attribute of immutable type 'dict'
```
it talks about setting the name rather than deleting it.
This is in https://github.com/python/cpython/blob/b48a3dbff4d70e72797e67b46276564fc63ddb89/Objects/typeobject.c#L1126
### CPython versions tested on:
3.10, 3.11, 3.12, 3.13
### Operating systems tested on:
Linux
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/119494">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>