]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
IDLE: Tweak iomenu.IOBinding.maybesave (#112914)
authorTerry Jan Reedy <tjreedy@udel.edu>
Sun, 10 Dec 2023 02:29:40 +0000 (21:29 -0500)
committerGitHub <noreply@github.com>
Sun, 10 Dec 2023 02:29:40 +0000 (21:29 -0500)
Add docstring, use f-string, simplify code.

Lib/idlelib/iomenu.py

index 667623ec71ac982b00ca94035fbd1e44deba075a..464126e2df0668200b80c97cf7d3e71c7a7e7492 100644 (file)
@@ -7,7 +7,7 @@ import tokenize
 
 from tkinter import filedialog
 from tkinter import messagebox
-from tkinter.simpledialog import askstring
+from tkinter.simpledialog import askstring  # loadfile encoding.
 
 from idlelib.config import idleConf
 from idlelib.util import py_extensions
@@ -180,24 +180,25 @@ class IOBinding:
         return True
 
     def maybesave(self):
+        """Return 'yes', 'no', 'cancel' as appropriate.
+
+        Tkinter messagebox.askyesnocancel converts these tk responses
+        to True, False, None.  Convert back, as now expected elsewhere.
+        """
         if self.get_saved():
             return "yes"
-        message = "Do you want to save %s before closing?" % (
-            self.filename or "this untitled document")
+        message = ("Do you want to save "
+                   f"{self.filename or 'this untitled document'}"
+                   " before closing?")
         confirm = messagebox.askyesnocancel(
                   title="Save On Close",
                   message=message,
                   default=messagebox.YES,
                   parent=self.text)
         if confirm:
-            reply = "yes"
             self.save(None)
-            if not self.get_saved():
-                reply = "cancel"
-        elif confirm is None:
-            reply = "cancel"
-        else:
-            reply = "no"
+            reply = "yes" if self.get_saved() else "cancel"
+        else:  reply = "cancel" if confirm is None else "no"
         self.text.focus_set()
         return reply