[issue43908] array.array should remain immutable: add Py_TPFLAGS_IMMUTABLETYPE flag

STINNER Victor report at bugs.python.org
Fri Apr 30 07:28:38 EDT 2021


STINNER Victor <vstinner at python.org> added the comment:

https://docs.python.org/dev/c-api/typeobj.html#Py_TPFLAGS_IMMUTABLETYPE says:
"This bit is set for type objects that are immutable: type attributes cannot be set nor deleted."

Is it possible that a metatype (type subtype) overrides tp_setattro and ignores the Py_TPFLAGS_IMMUTABLETYPE flag? Should we suggest that metatypes implemented in C and overridding tp_setattro should take the Py_TPFLAGS_IMMUTABLETYPE flag in account?

When a type overrides tp_setattro, I understand that it's fine since it's only used to set attributes of its instances, not on the type itself.

--

See also bpo-43770 "Rework C types initialization": some types explicitly sets explicitly tp_setattro to PyObject_GenericSetAttr. But it's unrelated since it's used to set attributes of type instances.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43908>
_______________________________________


More information about the Python-bugs-list mailing list