[Python-checkins] cpython: Issue #27609: Explicitly return None when there are other returns.

terry.reedy python-checkins at python.org
Sun Jul 24 20:35:55 EDT 2016


https://hg.python.org/cpython/rev/1ec47de72538
changeset:   102436:1ec47de72538
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Sun Jul 24 20:35:43 2016 -0400
summary:
  Issue #27609: Explicitly return None when there are other returns.
In a few cases, reverse a condition and eliminate a return.

files:
  Lib/idlelib/autocomplete.py   |  33 ++++++++++------------
  Lib/idlelib/autocomplete_w.py |  24 ++++++++--------
  2 files changed, 27 insertions(+), 30 deletions(-)


diff --git a/Lib/idlelib/autocomplete.py b/Lib/idlelib/autocomplete.py
--- a/Lib/idlelib/autocomplete.py
+++ b/Lib/idlelib/autocomplete.py
@@ -37,16 +37,14 @@
 
     def __init__(self, editwin=None):
         self.editwin = editwin
-        if editwin is None:  # subprocess and test
-            return
-        self.text = editwin.text
-        self.autocompletewindow = None
-
-        # id of delayed call, and the index of the text insert when the delayed
-        # call was issued. If _delayed_completion_id is None, there is no
-        # delayed call.
-        self._delayed_completion_id = None
-        self._delayed_completion_index = None
+        if editwin is not None:  # not in subprocess or test
+            self.text = editwin.text
+            self.autocompletewindow = None
+            # id of delayed call, and the index of the text insert when
+            # the delayed call was issued. If _delayed_completion_id is
+            # None, there is no delayed call.
+            self._delayed_completion_id = None
+            self._delayed_completion_index = None
 
     def _make_autocomplete_window(self):
         return autocomplete_w.AutoCompleteWindow(self.text)
@@ -82,7 +80,7 @@
         """
         if hasattr(event, "mc_state") and event.mc_state:
             # A modifier was pressed along with the tab, continue as usual.
-            return
+            return None
         if self.autocompletewindow and self.autocompletewindow.is_active():
             self.autocompletewindow.complete()
             return "break"
@@ -101,9 +99,8 @@
 
     def _delayed_open_completions(self, *args):
         self._delayed_completion_id = None
-        if self.text.index("insert") != self._delayed_completion_index:
-            return
-        self.open_completions(*args)
+        if self.text.index("insert") == self._delayed_completion_index:
+            self.open_completions(*args)
 
     def open_completions(self, evalfuncs, complete, userWantsWin, mode=None):
         """Find the completions and create the AutoCompleteWindow.
@@ -148,17 +145,17 @@
                 comp_what = hp.get_expression()
                 if not comp_what or \
                    (not evalfuncs and comp_what.find('(') != -1):
-                    return
+                    return None
             else:
                 comp_what = ""
         else:
-            return
+            return None
 
         if complete and not comp_what and not comp_start:
-            return
+            return None
         comp_lists = self.fetch_completions(comp_what, mode)
         if not comp_lists[0]:
-            return
+            return None
         self.autocompletewindow = self._make_autocomplete_window()
         return not self.autocompletewindow.show_window(
                 comp_lists, "insert-%dc" % len(comp_start),
diff --git a/Lib/idlelib/autocomplete_w.py b/Lib/idlelib/autocomplete_w.py
--- a/Lib/idlelib/autocomplete_w.py
+++ b/Lib/idlelib/autocomplete_w.py
@@ -216,6 +216,7 @@
         self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
         self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
                                           self.doubleclick_event)
+        return None
 
     def winconfig_event(self, event):
         if not self.is_active():
@@ -244,11 +245,10 @@
         self.hide_window()
 
     def listselect_event(self, event):
-        if not self.is_active():
-            return
-        self.userwantswindow = True
-        cursel = int(self.listbox.curselection()[0])
-        self._change_start(self.completions[cursel])
+        if self.is_active():
+            self.userwantswindow = True
+            cursel = int(self.listbox.curselection()[0])
+            self._change_start(self.completions[cursel])
 
     def doubleclick_event(self, event):
         # Put the selected completion in the text, and close the list
@@ -258,7 +258,7 @@
 
     def keypress_event(self, event):
         if not self.is_active():
-            return
+            return None
         keysym = event.keysym
         if hasattr(event, "mc_state"):
             state = event.mc_state
@@ -283,7 +283,7 @@
                 # keysym == "BackSpace"
                 if len(self.start) == 0:
                     self.hide_window()
-                    return
+                    return None
                 self._change_start(self.start[:-1])
             self.lasttypedstart = self.start
             self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
@@ -293,7 +293,7 @@
 
         elif keysym == "Return":
             self.hide_window()
-            return
+            return None
 
         elif (self.mode == COMPLETE_ATTRIBUTES and keysym in
               ("period", "space", "parenleft", "parenright", "bracketleft",
@@ -309,7 +309,7 @@
                and (self.mode == COMPLETE_ATTRIBUTES or self.start):
                 self._change_start(self.completions[cursel])
             self.hide_window()
-            return
+            return None
 
         elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
              not state:
@@ -350,12 +350,12 @@
                 # first tab; let AutoComplete handle the completion
                 self.userwantswindow = True
                 self.lastkey_was_tab = True
-                return
+                return None
 
         elif any(s in keysym for s in ("Shift", "Control", "Alt",
                                        "Meta", "Command", "Option")):
             # A modifier key, so ignore
-            return
+            return None
 
         elif event.char and event.char >= ' ':
             # Regular character with a non-length-1 keycode
@@ -369,7 +369,7 @@
         else:
             # Unknown event, close the window and let it through.
             self.hide_window()
-            return
+            return None
 
     def keyrelease_event(self, event):
         if not self.is_active():

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list