From 70c3e1ac74bbf68ca1908d141bb6aed211591025 Mon Sep 17 00:00:00 2001 From: abhi210 <27881020+Abhi210@users.noreply.github.com> Date: Sat, 27 Jun 2026 19:21:12 +0530 Subject: [PATCH 1/4] BUG: Fixe dealloc clears the in-flight exception in subtype_dealloc --- .../2026-07-11-14-39-38.gh-issue-151763.nlYxAk.rst | 2 ++ Objects/typeobject.c | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-07-11-14-39-38.gh-issue-151763.nlYxAk.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-11-14-39-38.gh-issue-151763.nlYxAk.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-11-14-39-38.gh-issue-151763.nlYxAk.rst new file mode 100644 index 000000000000000..4d54c2b82da6cbc --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-11-14-39-38.gh-issue-151763.nlYxAk.rst @@ -0,0 +1,2 @@ +Fixed a bug in free-threaded builds where the active exception could be +unexpectedly cleared during subtype deallocation in ``subtype_dealloc()``. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index b77f3e3bce54551..c66f245bdf329ab 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2833,6 +2833,13 @@ subtype_dealloc(PyObject *self) } } + /* Save the current exception: clear_slots() and the dict/base-dealloc + below decref arbitrary attribute values, which may clear + tstate->current_exception (gh-89373). Mirroring slot_tp_finalize(). */ + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *exc = _PyErr_GetRaisedException(tstate); /* preserve in-flight exception */ + + /* Clear slots up to the nearest base with a different tp_dealloc */ base = type; while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { @@ -2882,6 +2889,9 @@ subtype_dealloc(PyObject *self) if (type_needs_decref) { _Py_DECREF_TYPE(type); } + + /* Restore the saved exception (see save above). */ + _PyErr_SetRaisedException(tstate, exc); } static PyTypeObject *solid_base(PyTypeObject *type); From f6c44fe81b56f36d6590164fe6741aec17d98ed7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 11 Jul 2026 12:46:06 +0300 Subject: [PATCH 2/4] gh-86726: Fix and improve tkinter documentation and docstrings (GH-153549) Correct inaccurate return-type and option descriptions in the tkinter reference, and add missing module and class docstrings. Co-authored-by: Claude Opus 4.8 --- Doc/library/dialog.rst | 25 ++++++++++++------------- Doc/library/tkinter.messagebox.rst | 4 +--- Doc/library/tkinter.rst | 15 ++++++++------- Doc/library/tkinter.ttk.rst | 15 +++++++++++---- Lib/tkinter/__init__.py | 4 ++-- Lib/tkinter/colorchooser.py | 2 ++ Lib/tkinter/commondialog.py | 2 ++ Lib/tkinter/dialog.py | 7 ++++++- Lib/tkinter/font.py | 2 ++ Lib/tkinter/messagebox.py | 2 ++ Lib/tkinter/simpledialog.py | 2 +- 11 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Doc/library/dialog.rst b/Doc/library/dialog.rst index c18f2bb38b9ff1d..0d03eca88b62673 100644 --- a/Doc/library/dialog.rst +++ b/Doc/library/dialog.rst @@ -209,19 +209,16 @@ string, an empty tuple, an empty list or ``None``. .. class:: Open(master=None, **options) SaveAs(master=None, **options) + Directory(master=None, **options) - The above two classes provide native dialog windows for saving and loading - files. + The above three classes provide native dialog windows for loading and saving + files and for selecting a directory. **Convenience classes** The below classes are used for creating file/directory windows from scratch. These do not emulate the native look-and-feel of the platform. -.. class:: Directory(master=None, **options) - - Create a dialog prompting the user to select a directory. - .. note:: The *FileDialog* class should be subclassed for custom event handling and behaviour. @@ -361,23 +358,25 @@ the classic (non-themed) Tk widgets. .. data:: DIALOG_ICON - The name of the default bitmap (``'questhead'``) displayed by a - :class:`Dialog`. + The name of a bitmap (``'questhead'``) suitable for use as the *bitmap* + of a :class:`Dialog`. .. class:: Dialog(master=None, cnf={}, **kw) Display a modal dialog box built from the classic (non-themed) Tk widgets and wait for the user to press one of its buttons. - The options, given through *cnf* or as keyword arguments, include *title* - (the window title), *text* (the message), *bitmap* (an icon, - :data:`DIALOG_ICON` by default), *default* (the index of the default button) - and *strings* (the sequence of button labels). + The options, given through *cnf* or as keyword arguments, are all required: + *title* (the window title), *text* (the message), *bitmap* (the name of a + bitmap icon, such as :data:`DIALOG_ICON`), *default* (the index of the + default button) and *strings* (the sequence of button labels). After construction, the :attr:`!num` attribute holds the index of the button the user pressed. .. method:: destroy() - Destroy the dialog window. + Do nothing. + The dialog window is destroyed automatically before the constructor + returns, so there is nothing left for this method to do. .. seealso:: diff --git a/Doc/library/tkinter.messagebox.rst b/Doc/library/tkinter.messagebox.rst index 7fd561ade2f8bc5..47fe680bac9107e 100644 --- a/Doc/library/tkinter.messagebox.rst +++ b/Doc/library/tkinter.messagebox.rst @@ -13,9 +13,7 @@ a variety of convenience methods for commonly used configurations. The message boxes are modal: each blocks until the user responds, then returns a value that depends on the function. The ``show*`` functions and :meth:`Message.show` return the symbolic name of -the button the user pressed, as a string (such as :data:`OK` or :data:`YES`), -while the ``ask*`` functions return a :class:`bool` or ``None`` (see each -function below). +the button the user pressed, as a string (such as :data:`OK` or :data:`YES`). Common message box styles and layouts include but are not limited to: .. figure:: tk_msg.png diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index d2bd075c2e17d74..6962528b6a1fcd8 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -2356,8 +2356,8 @@ Base and mixin classes If all four arguments are given, the window manager keeps the ratio between ``minNumer/minDenom`` and ``maxNumer/maxDenom``; passing empty strings removes any existing restriction. - With no arguments, return a tuple of the four current values, or an empty - string if no aspect restriction is in effect. + With no arguments, return a tuple of the four current values, or ``None`` + if no aspect restriction is in effect. :meth:`wm_aspect` is an alias of :meth:`!aspect`. .. method:: wm_attributes(*args, return_python_dict=False, **kwargs) @@ -2582,8 +2582,8 @@ Base and mixin classes window's internally requested size, and *widthInc* and *heightInc* are the pixel sizes of a horizontal and vertical grid unit. Empty strings turn off gridded management. - With no arguments, return a tuple of the four current values, or an empty - string if the window is not gridded. + With no arguments, return a tuple of the four current values, or ``None`` + if the window is not gridded. :meth:`wm_grid` is an alias of :meth:`!grid`. Not to be confused with the grid geometry manager :meth:`Grid.grid`. @@ -2696,8 +2696,8 @@ Base and mixin classes Set or query a hint to the window manager about where the window's icon should be positioned. Empty strings cancel an existing hint. - With no arguments, return a tuple of the two current values, or an empty - string if no hint is in effect. + With no arguments, return a tuple of the two current values, or ``None`` + if no hint is in effect. :meth:`wm_iconposition` is an alias of :meth:`!iconposition`. .. method:: wm_iconwindow(pathName=None) @@ -2766,7 +2766,8 @@ Base and mixin classes When this flag is set, the window is ignored by the window manager: it is not reparented into a decorative frame and the user cannot manipulate it through the usual window manager controls. - With no argument, return a boolean indicating whether the flag is set. + With no argument, return a boolean indicating whether the flag is set, + or ``None`` if it has not been set. The flag is reliably honored only when the window is first mapped or remapped from the withdrawn state. :meth:`wm_overrideredirect` is an alias of :meth:`!overrideredirect`. diff --git a/Doc/library/tkinter.ttk.rst b/Doc/library/tkinter.ttk.rst index fdffa5ebb5da454..33cbaa3ca90d020 100644 --- a/Doc/library/tkinter.ttk.rst +++ b/Doc/library/tkinter.ttk.rst @@ -42,8 +42,9 @@ To override the basic Tk widgets, the import should follow the Tk import:: That code causes several :mod:`!tkinter.ttk` widgets (:class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :class:`Label`, -:class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`, -:class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`) to +:class:`LabelFrame`, :class:`Menubutton`, :class:`OptionMenu`, +:class:`PanedWindow`, :class:`Radiobutton`, :class:`Scale`, +:class:`Scrollbar` and :class:`Spinbox`) to automatically replace the Tk widgets. This has the direct benefit of using the new widgets which gives a better look @@ -1039,6 +1040,9 @@ ttk.Treeview The minimum width of the column in pixels. The treeview widget will not make the column any smaller than specified by this option when the widget is resized or the user drags a column. + *separator*: ``True``/``False`` + Specifies whether a column separator should be drawn to the right of + the column. *stretch*: ``True``/``False`` Specifies whether the column's width should be adjusted when the widget is resized. @@ -2167,8 +2171,11 @@ and inherits the common methods of :class:`Widget`. display in the menu. A *command* keyword argument may be given to specify a callable that is invoked with the selected value whenever the selection changes; the *style* - keyword argument sets the style used by the underlying menubutton; and the - *name* keyword argument sets the Tk widget name. + keyword argument sets the style used by the underlying menubutton; the + *direction* keyword argument sets where the menu is posted relative to the + menubutton (one of ``'above'``, ``'below'`` (the default), ``'left'``, + ``'right'`` or ``'flush'``); and the *name* keyword argument sets the Tk + widget name. .. method:: set_menu(default=None, *values) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index afc68726f7c8d5d..dde4accecf61ba4 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -3,7 +3,7 @@ Tkinter provides classes which allow the display, positioning and control of widgets. Toplevel widgets are Tk and Toplevel. Other widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton, -Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox +Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox, LabelFrame and PanedWindow. Properties of the widgets are specified with keyword arguments. @@ -2528,7 +2528,7 @@ def wm_iconphoto(self, default=False, *args): # new in Tk 8.5 def wm_iconposition(self, x=None, y=None): """Set the position of the icon of this widget to X and Y. Return - a tuple of the current values of X and X if None is given.""" + a tuple of the current values of X and Y if None is given.""" return self._getints(self.tk.call( 'wm', 'iconposition', self._w, x, y)) diff --git a/Lib/tkinter/colorchooser.py b/Lib/tkinter/colorchooser.py index e2fb69dba927633..4085bde1637a79f 100644 --- a/Lib/tkinter/colorchooser.py +++ b/Lib/tkinter/colorchooser.py @@ -1,3 +1,5 @@ +"""Interface to the native Tk color selection dialog.""" + # tk common color chooser dialogue # # this module provides an interface to the native color dialogue diff --git a/Lib/tkinter/commondialog.py b/Lib/tkinter/commondialog.py index 86f5387e001bf28..408cedc345def63 100644 --- a/Lib/tkinter/commondialog.py +++ b/Lib/tkinter/commondialog.py @@ -1,3 +1,5 @@ +"""Base class for the Tk common dialogs.""" + # base class for tk common dialogues # # this module provides a base class for accessing the common diff --git a/Lib/tkinter/dialog.py b/Lib/tkinter/dialog.py index 36ae6c277cb66ac..ef005af0d5a19c0 100644 --- a/Lib/tkinter/dialog.py +++ b/Lib/tkinter/dialog.py @@ -1,5 +1,7 @@ # dialog.py -- Tkinter interface to the tk_dialog script. +"""Classic Tk dialog box, wrapping the tk_dialog script.""" + from tkinter import _cnfmerge, Widget, TclError, Button, Pack __all__ = ["Dialog"] @@ -8,6 +10,8 @@ class Dialog(Widget): + """A modal dialog box built from the classic (non-themed) Tk widgets.""" + def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = '__dialog__' @@ -21,7 +25,8 @@ def __init__(self, master=None, cnf={}, **kw): try: Widget.destroy(self) except TclError: pass - def destroy(self): pass + def destroy(self): + """Do nothing; the dialog window is already destroyed.""" def _test(): diff --git a/Lib/tkinter/font.py b/Lib/tkinter/font.py index 7ce7047885fce5f..5b663a4e456456b 100644 --- a/Lib/tkinter/font.py +++ b/Lib/tkinter/font.py @@ -1,3 +1,5 @@ +"""Utilities to help work with fonts in Tkinter.""" + # Tkinter font wrapper # # written by Fredrik Lundh, February 1998 diff --git a/Lib/tkinter/messagebox.py b/Lib/tkinter/messagebox.py index dd2816cffb1140b..f6848142a9aff62 100644 --- a/Lib/tkinter/messagebox.py +++ b/Lib/tkinter/messagebox.py @@ -1,3 +1,5 @@ +"""Interface to the standard Tk message boxes.""" + # tk common message boxes # # this module provides an interface to the native message boxes diff --git a/Lib/tkinter/simpledialog.py b/Lib/tkinter/simpledialog.py index c61881d48724217..1b0cf51317ee082 100644 --- a/Lib/tkinter/simpledialog.py +++ b/Lib/tkinter/simpledialog.py @@ -8,7 +8,7 @@ # fredrik@pythonware.com # http://www.pythonware.com # -"""This modules handles dialog boxes. +"""This module handles dialog boxes. It contains the following public symbols: From 497282ee92f15f6ce6f6a9a49342783dbebc6273 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 11 Jul 2026 12:49:12 +0300 Subject: [PATCH 3/4] gh-126877: Fix the configure check for Tcl/Tk with optimizing compilers (GH-153543) The check assigned the addresses of Tcl_Init() and Tk_Init() to unused variables, which optimizing compilers can eliminate, so it linked even when the libraries were missing. Call the functions instead. Co-authored-by: Claude Opus 4.8 --- .../next/Build/2026-07-11-07-26-16.gh-issue-126877.Zt7Kq2.rst | 2 ++ configure | 4 ++-- configure.ac | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-07-11-07-26-16.gh-issue-126877.Zt7Kq2.rst diff --git a/Misc/NEWS.d/next/Build/2026-07-11-07-26-16.gh-issue-126877.Zt7Kq2.rst b/Misc/NEWS.d/next/Build/2026-07-11-07-26-16.gh-issue-126877.Zt7Kq2.rst new file mode 100644 index 000000000000000..1d7d4fad886c56f --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-07-11-07-26-16.gh-issue-126877.Zt7Kq2.rst @@ -0,0 +1,2 @@ +Fix the :program:`configure` check for Tcl/Tk which could wrongly succeed +with optimizing compilers when the libraries are missing. diff --git a/configure b/configure index 17b7ef765cc7fdf..c15bc2867b94d7d 100755 --- a/configure +++ b/configure @@ -17975,8 +17975,8 @@ int main (void) { - void *x1 = Tcl_Init; - void *x2 = Tk_Init; + Tcl_Init(NULL); + Tk_Init(NULL); ; return 0; diff --git a/configure.ac b/configure.ac index ab64ac8769b5515..2726a835efc5449 100644 --- a/configure.ac +++ b/configure.ac @@ -4618,8 +4618,8 @@ WITH_SAVE_ENV([ # error "Tk older than 8.5.12 not supported" #endif ], [ - void *x1 = Tcl_Init; - void *x2 = Tk_Init; + Tcl_Init(NULL); + Tk_Init(NULL); ]) ], [ have_tcltk=yes From 6924391a66e98289cdeca32a2eb898af9a6828fd Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 11 Jul 2026 13:10:27 +0300 Subject: [PATCH 4/4] gh-86726: Note that the ttk Treeview separator column option needs Tk 9.0 (GH-153556) Co-authored-by: Claude Opus 4.8 --- Doc/library/tkinter.ttk.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/tkinter.ttk.rst b/Doc/library/tkinter.ttk.rst index 33cbaa3ca90d020..353dcacb79f4e38 100644 --- a/Doc/library/tkinter.ttk.rst +++ b/Doc/library/tkinter.ttk.rst @@ -884,8 +884,8 @@ This widget accepts the following specific options: The *selectmode* option gained the values ``"single"`` and ``"multiple"``; the new widget options *selecttype* (``"item"`` or ``"cell"`` selection), *striped* (zebra-striped rows), and *titlecolumns* / *titleitems* (columns - or rows frozen against scrolling) were introduced; and items gained a - *hidden* option. + or rows frozen against scrolling) were introduced; the column *separator* + option was added; and items gained a *hidden* option. Tk 9.1 added the *rowheight* and *headingheight* options.