bpo-43908: Add Py_TPFLAGS_IMMUTABLETYPE flag (GH-25520) · python/cpython@3b52c8d · GitHub
Skip to content

Commit 3b52c8d

Browse files
Erlend Egeberg Aaslandvstinner
andauthored
bpo-43908: Add Py_TPFLAGS_IMMUTABLETYPE flag (GH-25520)
Introduce Py_TPFLAGS_IMMUTABLETYPE flag for immutable type objects, and modify PyType_Ready() to set it for static types. Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 3cc481b commit 3b52c8d

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

Doc/c-api/typeobj.rst

Lines changed: 12 additions & 0 deletions

Include/object.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
320320
given type object has a specified feature.
321321
*/
322322

323+
/* Set if the type object is immutable: type attributes cannot be set nor deleted */
324+
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
325+
323326
/* Set if the type object is dynamically allocated */
324327
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
325328

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Introduce :const:`Py_TPFLAGS_IMMUTABLETYPE` flag for immutable type objects, and
2+
modify :c:func:`PyType_Ready` to set it for static types. Patch by
3+
Erlend E. Aasland.

Objects/typeobject.c

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)