From 715f5debdb16601d14cd3c0f468084ab61273223 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 27 Jun 2026 18:21:50 +0300 Subject: [PATCH 1/3] gh-103878: Document that the cancelled file dialog value is only falsy Its exact type (empty string, tuple, list or None) varies between platforms and Tk versions, so advise testing the result for truth. Co-Authored-By: Claude Opus 4.8 --- Doc/library/dialog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/dialog.rst b/Doc/library/dialog.rst index 74b23eaf87b4a0b..a6a7979d39c5406 100644 --- a/Doc/library/dialog.rst +++ b/Doc/library/dialog.rst @@ -160,6 +160,9 @@ The below functions when called create a modal, native look-and-feel dialog, wait for the user's selection, and return it. The exact return value depends on the function (see below); when the dialog is cancelled it is an empty string, an empty tuple, an empty list or ``None``. +The precise type of this empty value may vary between platforms and Tk +versions, so test the result for truth rather than comparing it with a +specific value. .. function:: askopenfile(mode="r", **options) askopenfiles(mode="r", **options) From e265aa0ee43ca666d505f6ad027f5e578f3b5ab3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 27 Jun 2026 19:58:35 +0300 Subject: [PATCH 2/3] gh-103878: Fix the documented cancelled value of askopenfiles() askopenfiles() returns an empty tuple, not an empty list, when cancelled. Co-Authored-By: Claude Opus 4.8 --- Doc/library/dialog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/dialog.rst b/Doc/library/dialog.rst index a6a7979d39c5406..119edef8a7c2cd2 100644 --- a/Doc/library/dialog.rst +++ b/Doc/library/dialog.rst @@ -171,7 +171,7 @@ specific value. :func:`askopenfile` returns the opened file object, or ``None`` if the dialog is cancelled. :func:`askopenfiles` returns a list of the opened file objects, or an empty - list if cancelled. + tuple if cancelled. The files are opened in mode *mode* (read-only ``'r'`` by default). .. function:: asksaveasfile(mode="w", **options) From 87263b2b8f6b9364025213a6acb2fb83e334e9d2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 27 Jun 2026 20:00:07 +0300 Subject: [PATCH 3/3] gh-103878: Drop "an empty list" from the cancelled-value list No file dialog function returns an empty list on cancellation. Co-Authored-By: Claude Opus 4.8 --- Doc/library/dialog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/dialog.rst b/Doc/library/dialog.rst index 119edef8a7c2cd2..c3f62117ed61d78 100644 --- a/Doc/library/dialog.rst +++ b/Doc/library/dialog.rst @@ -159,7 +159,7 @@ listed below: The below functions when called create a modal, native look-and-feel dialog, wait for the user's selection, and return it. The exact return value depends on the function (see below); when the dialog is -cancelled it is an empty string, an empty tuple, an empty list or ``None``. +cancelled it is an empty string, an empty tuple or ``None``. The precise type of this empty value may vary between platforms and Tk versions, so test the result for truth rather than comparing it with a specific value.