[Python-checkins] bpo-38636: Fix IDLE tab toggle and file indent width (GH-17008)

Miss Islington (bot) webhook-mailer at python.org
Wed Nov 20 01:37:14 EST 2019


https://github.com/python/cpython/commit/755caaa753577b907bb7e94560f8adf5eb694d6b
commit: 755caaa753577b907bb7e94560f8adf5eb694d6b
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-11-19T22:37:09-08:00
summary:

bpo-38636: Fix IDLE tab toggle and file indent width (GH-17008)


These Format menu functions (default shortcuts Alt-T and Alt-U)
were mistakenly disabled in 3.7.5 and 3.8.0.
(cherry picked from commit b8462477bfd01ff21461065d5063e6b0238ca809)

Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>

files:
A Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/editor.py
M Lib/idlelib/format.py
M Lib/idlelib/idle_test/test_format.py

diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 2fd2ea19b5a0f..53348ee0af0e9 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,10 @@ Released on 2019-12-16?
 ======================================
 
 
+bpo-38636: Fix IDLE Format menu tab toggle and file indent width. These
+functions (default shortcuts Alt-T and Alt-U) were mistakenly disabled
+in 3.7.5 and 3.8.0.
+
 bpo-4360: Add an option to toggle IDLE's cursor blink for shell,
 editor, and output windows.  See Settings, General, Window Preferences,
 Cursor Blink.  Patch by Zachary Spytz.
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index dff104ff0f18f..92dcf57c4ff26 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -186,8 +186,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
         text.bind("<<uncomment-region>>", fregion.uncomment_region_event)
         text.bind("<<tabify-region>>", fregion.tabify_region_event)
         text.bind("<<untabify-region>>", fregion.untabify_region_event)
-        text.bind("<<toggle-tabs>>", self.Indents.toggle_tabs_event)
-        text.bind("<<change-indentwidth>>", self.Indents.change_indentwidth_event)
+        indents = self.Indents(self)
+        text.bind("<<toggle-tabs>>", indents.toggle_tabs_event)
+        text.bind("<<change-indentwidth>>", indents.change_indentwidth_event)
         text.bind("<Left>", self.move_at_edge_if_selection(0))
         text.bind("<Right>", self.move_at_edge_if_selection(1))
         text.bind("<<del-word-left>>", self.del_word_left)
diff --git a/Lib/idlelib/format.py b/Lib/idlelib/format.py
index bced4c1770eb0..2b0980565734a 100644
--- a/Lib/idlelib/format.py
+++ b/Lib/idlelib/format.py
@@ -353,8 +353,7 @@ def _asktabwidth(self):
             maxvalue=16)
 
 
-# With mixed indents not allowed, these are semi-useless and not unittested.
-class Indents:  # pragma: no cover
+class Indents:
     "Change future indents."
 
     def __init__(self, editwin):
diff --git a/Lib/idlelib/idle_test/test_format.py b/Lib/idlelib/idle_test/test_format.py
index c7b123e9d513a..20b5970f4982d 100644
--- a/Lib/idlelib/idle_test/test_format.py
+++ b/Lib/idlelib/idle_test/test_format.py
@@ -417,7 +417,7 @@ def tearDown(self):
         self.text.delete('1.0', 'end')
 
     code_sample = """\
-
+# WS line needed for test.
 class C1():
     # Class comment.
     def __init__(self, a, b):
@@ -574,7 +574,42 @@ def test_ask_tabwidth(self, askinteger):
         self.assertEqual(ask(), 10)
 
 
-class rstripTest(unittest.TestCase):
+class IndentsTest(unittest.TestCase):
+
+    @mock.patch.object(ft, "askyesno")
+    def test_toggle_tabs(self, askyesno):
+        editor = DummyEditwin(None, None)  # usetabs == False.
+        indents = ft.Indents(editor)
+        askyesno.return_value = True
+
+        indents.toggle_tabs_event(None)
+        self.assertEqual(editor.usetabs, True)
+        self.assertEqual(editor.indentwidth, 8)
+
+        indents.toggle_tabs_event(None)
+        self.assertEqual(editor.usetabs, False)
+        self.assertEqual(editor.indentwidth, 8)
+
+    @mock.patch.object(ft, "askinteger")
+    def test_change_indentwidth(self, askinteger):
+        editor = DummyEditwin(None, None)  # indentwidth == 4.
+        indents = ft.Indents(editor)
+
+        askinteger.return_value = None
+        indents.change_indentwidth_event(None)
+        self.assertEqual(editor.indentwidth, 4)
+
+        askinteger.return_value = 3
+        indents.change_indentwidth_event(None)
+        self.assertEqual(editor.indentwidth, 3)
+
+        askinteger.return_value = 5
+        editor.usetabs = True
+        indents.change_indentwidth_event(None)
+        self.assertEqual(editor.indentwidth, 3)
+
+
+class RstripTest(unittest.TestCase):
 
     def test_rstrip_line(self):
         editor = MockEditor()
diff --git a/Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst b/Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst
new file mode 100644
index 0000000000000..4262dbea6d867
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst
@@ -0,0 +1,3 @@
+Fix IDLE Format menu tab toggle and file indent width. These functions
+(default shortcuts Alt-T and Alt-U) were mistakenly disabled in 3.7.5
+and 3.8.0.



More information about the Python-checkins mailing list