-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
This is a fairly minor bug - the behaviour the interpreter disallows looks correct but the error messages look unhelpful.
>>> 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
Line 1126 in b48a3db
| check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *name) |
CPython versions tested on:
3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error