From 53c9fe80cceeb997767c2eab2f5f11eda6f502ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:35:29 +0200 Subject: [PATCH 01/10] make `_tkinter.Tcl_Obj` immutable --- Modules/_tkinter.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index d921c46d645ac0..b3b2629ef5001a 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -906,11 +906,14 @@ static PyType_Slot PyTclObject_Type_slots[] = { }; static PyType_Spec PyTclObject_Type_spec = { - "_tkinter.Tcl_Obj", - sizeof(PyTclObject), - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, - PyTclObject_Type_slots, + .name = "_tkinter.Tcl_Obj", + .basicsize = sizeof(PyTclObject), + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE + ), + .slots = PyTclObject_Type_slots, }; From 8db011335e99bc21231ad3dfa3559c00e418fdcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:36:03 +0200 Subject: [PATCH 02/10] make `_curses_panel.panel` immutable --- Modules/_curses_panel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index 66a8c40953da8c..3b46fdf838b16f 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -684,6 +684,7 @@ static PyType_Spec PyCursesPanel_Type_spec = { .flags = ( Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ), .slots = PyCursesPanel_Type_slots From c7213ac07acec82651c081ba764cf184c1a9ed4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:36:47 +0200 Subject: [PATCH 03/10] make `_tkinter.tkapp` immutable --- Modules/_tkinter.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index b3b2629ef5001a..d38f80a00b7cad 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -3326,11 +3326,14 @@ static PyType_Slot Tkapp_Type_slots[] = { static PyType_Spec Tkapp_Type_spec = { - "_tkinter.tkapp", - sizeof(TkappObject), - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, - Tkapp_Type_slots, + .name = "_tkinter.tkapp", + .basicsize = sizeof(TkappObject), + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE + ), + .slots = Tkapp_Type_slots, }; static PyMethodDef moduleMethods[] = From 443908f582add0bc17e8383b16b9ad405e5e5198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:37:15 +0200 Subject: [PATCH 04/10] make `_tkinter.tktimertoken` immutable --- Modules/_tkinter.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index d38f80a00b7cad..f0882191d3c3e8 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -3270,11 +3270,14 @@ static PyType_Slot Tktt_Type_slots[] = { }; static PyType_Spec Tktt_Type_spec = { - "_tkinter.tktimertoken", - sizeof(TkttObject), - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, - Tktt_Type_slots, + .name = "_tkinter.tktimertoken", + .basicsize = sizeof(TkttObject), + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE + ), + .slots = Tktt_Type_slots, }; From 2ceb790da6d6c32482b8ed67ea6b3231bfc35715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:38:10 +0200 Subject: [PATCH 05/10] make `zlib.Compress` immutable --- Modules/zlibmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 0625a6f8052b6c..8eff545919b143 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -2043,6 +2043,7 @@ static PyType_Spec Comptype_spec = { .flags = ( Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ), .slots= Comptype_slots, From 2b0f8efaa337109c760964d185c84cd36e5bd497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:38:18 +0200 Subject: [PATCH 06/10] make `zlib.Decompress` immutable --- Modules/zlibmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 8eff545919b143..1ee14e31612860 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -2063,6 +2063,7 @@ static PyType_Spec Decomptype_spec = { .flags = ( Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC ), .slots = Decomptype_slots, From ba552636c4bcba0ae0e5b7d3f3bd3376ee156219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:42:35 +0200 Subject: [PATCH 07/10] make `[posix,nt].ScandirIterator` immutable --- Modules/posixmodule.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 53b21e99376485..fff6fa4dadda00 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -16477,14 +16477,17 @@ static PyType_Slot ScandirIteratorType_slots[] = { }; static PyType_Spec ScandirIteratorType_spec = { - MODNAME ".ScandirIterator", - sizeof(ScandirIterator), - 0, + .name = MODNAME ".ScandirIterator", + .basicsize = sizeof(ScandirIterator), // bpo-40549: Py_TPFLAGS_BASETYPE should not be used, since // PyType_GetModule(Py_TYPE(self)) doesn't work on a subclass instance. - (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_FINALIZE - | Py_TPFLAGS_DISALLOW_INSTANTIATION), - ScandirIteratorType_slots + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_HAVE_FINALIZE + | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE + ), + .slots = ScandirIteratorType_slots }; /*[clinic input] From 934432e15e380144836541796c518ac0a907f6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:45:21 +0200 Subject: [PATCH 08/10] make `[posix,nt].DirEntry` immutable --- Modules/posixmodule.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index fff6fa4dadda00..45a60183b07e18 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -16035,11 +16035,14 @@ static PyType_Slot DirEntryType_slots[] = { }; static PyType_Spec DirEntryType_spec = { - MODNAME ".DirEntry", - sizeof(DirEntry), - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, - DirEntryType_slots + .name = MODNAME ".DirEntry", + .basicsize = sizeof(DirEntry), + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE + ), + .slots = DirEntryType_slots }; From 60f9545097083445e0fed70e05929b108bc191dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 15:22:42 +0200 Subject: [PATCH 09/10] make `_remote_debugging.RemoteUnwinder` immutable --- Modules/_remote_debugging_module.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_remote_debugging_module.c b/Modules/_remote_debugging_module.c index d261f179952039..1acac47b1b0ecc 100644 --- a/Modules/_remote_debugging_module.c +++ b/Modules/_remote_debugging_module.c @@ -2994,7 +2994,10 @@ static PyType_Slot RemoteUnwinder_slots[] = { static PyType_Spec RemoteUnwinder_spec = { .name = "_remote_debugging.RemoteUnwinder", .basicsize = sizeof(RemoteUnwinderObject), - .flags = Py_TPFLAGS_DEFAULT, + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_IMMUTABLETYPE + ), .slots = RemoteUnwinder_slots, }; From 6405c1cbe556e6a2026595c03084f309b7b57bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 6 Sep 2025 15:17:41 +0200 Subject: [PATCH 10/10] blurb --- .../Library/2025-09-06-14-47-23.gh-issue-116946.hj_u1t.rst | 5 +++++ .../Library/2025-09-06-14-53-19.gh-issue-116946.c-npxd.rst | 2 ++ .../Library/2025-09-06-14-54-01.gh-issue-116946.hzQEWI.rst | 3 +++ .../Library/2025-09-06-14-56-40.gh-issue-116946.GGIeyO.rst | 2 ++ 4 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-09-06-14-47-23.gh-issue-116946.hj_u1t.rst create mode 100644 Misc/NEWS.d/next/Library/2025-09-06-14-53-19.gh-issue-116946.c-npxd.rst create mode 100644 Misc/NEWS.d/next/Library/2025-09-06-14-54-01.gh-issue-116946.hzQEWI.rst create mode 100644 Misc/NEWS.d/next/Library/2025-09-06-14-56-40.gh-issue-116946.GGIeyO.rst diff --git a/Misc/NEWS.d/next/Library/2025-09-06-14-47-23.gh-issue-116946.hj_u1t.rst b/Misc/NEWS.d/next/Library/2025-09-06-14-47-23.gh-issue-116946.hj_u1t.rst new file mode 100644 index 00000000000000..b078070166c26d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-06-14-47-23.gh-issue-116946.hj_u1t.rst @@ -0,0 +1,5 @@ +:mod:`tkinter`: the types :class:`!_tkinter.Tcl_Obj` (wrapper for Tcl objects), +:class:`!_tkinter.tktimertoken` (obtained by calling ``createtimerhandler()`` +on a :attr:`Tk ` application) and :class:`!_tkinter.tkapp` +(the runtime type of Tk applications) are now immutable. +Patch by Bénédikt Tran. diff --git a/Misc/NEWS.d/next/Library/2025-09-06-14-53-19.gh-issue-116946.c-npxd.rst b/Misc/NEWS.d/next/Library/2025-09-06-14-53-19.gh-issue-116946.c-npxd.rst new file mode 100644 index 00000000000000..7d7d7ac5b289f3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-06-14-53-19.gh-issue-116946.c-npxd.rst @@ -0,0 +1,2 @@ +:mod:`os`: the :class:`os.DirEntry` type and the type of :func:`os.scandir` +are now immutable. Patch by Bénédikt Tran. diff --git a/Misc/NEWS.d/next/Library/2025-09-06-14-54-01.gh-issue-116946.hzQEWI.rst b/Misc/NEWS.d/next/Library/2025-09-06-14-54-01.gh-issue-116946.hzQEWI.rst new file mode 100644 index 00000000000000..91c03fc740463f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-06-14-54-01.gh-issue-116946.hzQEWI.rst @@ -0,0 +1,3 @@ +:mod:`zlib`: the types of :func:`zlib.compressobj` +and :func:`zlib.decompressobj` are now immutable. +Patch by Bénédikt Tran. diff --git a/Misc/NEWS.d/next/Library/2025-09-06-14-56-40.gh-issue-116946.GGIeyO.rst b/Misc/NEWS.d/next/Library/2025-09-06-14-56-40.gh-issue-116946.GGIeyO.rst new file mode 100644 index 00000000000000..90cf43b788137f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-06-14-56-40.gh-issue-116946.GGIeyO.rst @@ -0,0 +1,2 @@ +:mod:`curses.panel`: the type of :func:`curses.panel.new_panel` is now +immutable. Patch by Bénédikt Tran.