Skip to content

Commit 4978bfc

Browse files
authored
gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to several internal types (#138582)
The following types are now immutable: * `_curses_panel.panel`, * `[posix,nt].ScandirIterator`, `[posix,nt].DirEntry` (exposed in `os.py`), * `_remote_debugging.RemoteUnwinder`, * `_tkinter.Tcl_Obj`, `_tkinter.tkapp`, `_tkinter.tktimertoken`, * `zlib.Compress`, and `zlib.Decompress`.
1 parent 859aecc commit 4978bfc

9 files changed

+60
-27
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:mod:`tkinter`: the types :class:`!_tkinter.Tcl_Obj` (wrapper for Tcl objects),
2+
:class:`!_tkinter.tktimertoken` (obtained by calling ``createtimerhandler()``
3+
on a :attr:`Tk <tkinter.Tk.tk>` application) and :class:`!_tkinter.tkapp`
4+
(the runtime type of Tk applications) are now immutable.
5+
Patch by Bénédikt Tran.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`os`: the :class:`os.DirEntry` type and the type of :func:`os.scandir`
2+
are now immutable. Patch by Bénédikt Tran.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`zlib`: the types of :func:`zlib.compressobj`
2+
and :func:`zlib.decompressobj` are now immutable.
3+
Patch by Bénédikt Tran.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`curses.panel`: the type of :func:`curses.panel.new_panel` is now
2+
immutable. Patch by Bénédikt Tran.

Modules/_curses_panel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ static PyType_Spec PyCursesPanel_Type_spec = {
684684
.flags = (
685685
Py_TPFLAGS_DEFAULT
686686
| Py_TPFLAGS_DISALLOW_INSTANTIATION
687+
| Py_TPFLAGS_IMMUTABLETYPE
687688
| Py_TPFLAGS_HAVE_GC
688689
),
689690
.slots = PyCursesPanel_Type_slots

Modules/_remote_debugging_module.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3062,7 +3062,10 @@ static PyType_Slot RemoteUnwinder_slots[] = {
30623062
static PyType_Spec RemoteUnwinder_spec = {
30633063
.name = "_remote_debugging.RemoteUnwinder",
30643064
.basicsize = sizeof(RemoteUnwinderObject),
3065-
.flags = Py_TPFLAGS_DEFAULT,
3065+
.flags = (
3066+
Py_TPFLAGS_DEFAULT
3067+
| Py_TPFLAGS_IMMUTABLETYPE
3068+
),
30663069
.slots = RemoteUnwinder_slots,
30673070
};
30683071

Modules/_tkinter.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,14 @@ static PyType_Slot PyTclObject_Type_slots[] = {
906906
};
907907

908908
static PyType_Spec PyTclObject_Type_spec = {
909-
"_tkinter.Tcl_Obj",
910-
sizeof(PyTclObject),
911-
0,
912-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
913-
PyTclObject_Type_slots,
909+
.name = "_tkinter.Tcl_Obj",
910+
.basicsize = sizeof(PyTclObject),
911+
.flags = (
912+
Py_TPFLAGS_DEFAULT
913+
| Py_TPFLAGS_DISALLOW_INSTANTIATION
914+
| Py_TPFLAGS_IMMUTABLETYPE
915+
),
916+
.slots = PyTclObject_Type_slots,
914917
};
915918

916919

@@ -3267,11 +3270,14 @@ static PyType_Slot Tktt_Type_slots[] = {
32673270
};
32683271

32693272
static PyType_Spec Tktt_Type_spec = {
3270-
"_tkinter.tktimertoken",
3271-
sizeof(TkttObject),
3272-
0,
3273-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
3274-
Tktt_Type_slots,
3273+
.name = "_tkinter.tktimertoken",
3274+
.basicsize = sizeof(TkttObject),
3275+
.flags = (
3276+
Py_TPFLAGS_DEFAULT
3277+
| Py_TPFLAGS_DISALLOW_INSTANTIATION
3278+
| Py_TPFLAGS_IMMUTABLETYPE
3279+
),
3280+
.slots = Tktt_Type_slots,
32753281
};
32763282

32773283

@@ -3323,11 +3329,14 @@ static PyType_Slot Tkapp_Type_slots[] = {
33233329

33243330

33253331
static PyType_Spec Tkapp_Type_spec = {
3326-
"_tkinter.tkapp",
3327-
sizeof(TkappObject),
3328-
0,
3329-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
3330-
Tkapp_Type_slots,
3332+
.name = "_tkinter.tkapp",
3333+
.basicsize = sizeof(TkappObject),
3334+
.flags = (
3335+
Py_TPFLAGS_DEFAULT
3336+
| Py_TPFLAGS_DISALLOW_INSTANTIATION
3337+
| Py_TPFLAGS_IMMUTABLETYPE
3338+
),
3339+
.slots = Tkapp_Type_slots,
33313340
};
33323341

33333342
static PyMethodDef moduleMethods[] =

Modules/posixmodule.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16050,11 +16050,14 @@ static PyType_Slot DirEntryType_slots[] = {
1605016050
};
1605116051

1605216052
static PyType_Spec DirEntryType_spec = {
16053-
MODNAME ".DirEntry",
16054-
sizeof(DirEntry),
16055-
0,
16056-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
16057-
DirEntryType_slots
16053+
.name = MODNAME ".DirEntry",
16054+
.basicsize = sizeof(DirEntry),
16055+
.flags = (
16056+
Py_TPFLAGS_DEFAULT
16057+
| Py_TPFLAGS_DISALLOW_INSTANTIATION
16058+
| Py_TPFLAGS_IMMUTABLETYPE
16059+
),
16060+
.slots = DirEntryType_slots
1605816061
};
1605916062

1606016063

@@ -16492,14 +16495,17 @@ static PyType_Slot ScandirIteratorType_slots[] = {
1649216495
};
1649316496

1649416497
static PyType_Spec ScandirIteratorType_spec = {
16495-
MODNAME ".ScandirIterator",
16496-
sizeof(ScandirIterator),
16497-
0,
16498+
.name = MODNAME ".ScandirIterator",
16499+
.basicsize = sizeof(ScandirIterator),
1649816500
// bpo-40549: Py_TPFLAGS_BASETYPE should not be used, since
1649916501
// PyType_GetModule(Py_TYPE(self)) doesn't work on a subclass instance.
16500-
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_FINALIZE
16501-
| Py_TPFLAGS_DISALLOW_INSTANTIATION),
16502-
ScandirIteratorType_slots
16502+
.flags = (
16503+
Py_TPFLAGS_DEFAULT
16504+
| Py_TPFLAGS_HAVE_FINALIZE
16505+
| Py_TPFLAGS_DISALLOW_INSTANTIATION
16506+
| Py_TPFLAGS_IMMUTABLETYPE
16507+
),
16508+
.slots = ScandirIteratorType_slots
1650316509
};
1650416510

1650516511
/*[clinic input]

Modules/zlibmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ static PyType_Spec Comptype_spec = {
20432043
.flags = (
20442044
Py_TPFLAGS_DEFAULT
20452045
| Py_TPFLAGS_DISALLOW_INSTANTIATION
2046+
| Py_TPFLAGS_IMMUTABLETYPE
20462047
| Py_TPFLAGS_HAVE_GC
20472048
),
20482049
.slots= Comptype_slots,
@@ -2062,6 +2063,7 @@ static PyType_Spec Decomptype_spec = {
20622063
.flags = (
20632064
Py_TPFLAGS_DEFAULT
20642065
| Py_TPFLAGS_DISALLOW_INSTANTIATION
2066+
| Py_TPFLAGS_IMMUTABLETYPE
20652067
| Py_TPFLAGS_HAVE_GC
20662068
),
20672069
.slots = Decomptype_slots,

0 commit comments

Comments
 (0)