Skip to content

Commit fedf797

Browse files
committed
Comments are better and modern
1 parent f303e5d commit fedf797

File tree

4 files changed

+45
-54
lines changed

4 files changed

+45
-54
lines changed

Lib/idlelib/autocomplete.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"""Complete either attribute names or file names.
1+
# Complete either attribute names or file names.
2+
3+
# Either on demand or after a user-selected delay after a key character,
4+
# pop up a list of candidates.
25

3-
Either on demand or after a user-selected delay after a key character,
4-
pop up a list of candidates.
5-
"""
66
import __main__
77
import keyword
88
import os
@@ -93,18 +93,17 @@ def try_open_completions_event(self, event=None):
9393
self.popupwait, self._delayed_open_completions, args)
9494

9595
def _delayed_open_completions(self, args):
96-
"Call open_completions if index unchanged."
96+
# Call open_completions if index unchanged.
9797
self._delayed_completion_id = None
9898
if self.text.index("insert") == self._delayed_completion_index:
9999
self.open_completions(args)
100100

101101
def open_completions(self, args):
102-
"""Find the completions and create the AutoCompleteWindow.
103-
Return True if successful (no syntax error or so found).
104-
If complete is True, then if there's nothing to complete and no
105-
start of completion, won't open completions and return False.
106-
If mode is given, will open a completion list only in this mode.
107-
"""
102+
# Find the completions and create the AutoCompleteWindow.
103+
# Return True if successful (no syntax error or so found).
104+
# If complete is True, then if there's nothing to complete and no
105+
# start of completion, won't open completions and return False. If mode is given, will open a completion list only in this mode.
106+
108107
evalfuncs, complete, wantwin, mode = args
109108
# Cancel another delayed call, if it exists.
110109
if self._delayed_completion_id is not None:
@@ -115,11 +114,13 @@ def open_completions(self, args):
115114
curline = self.text.get("insert linestart", "insert")
116115
i = j = len(curline)
117116
if hp.is_in_string() and (not mode or mode==FILES):
117+
118118
# Find the beginning of the string.
119119
# fetch_completions will look at the file system to determine
120120
# whether the string value constitutes an actual file name
121121
# XXX could consider raw strings here and unescape the string
122122
# value if it's not raw.
123+
123124
self._remove_autocomplete_window()
124125
mode = FILES
125126
# Find last separator or string start
@@ -159,17 +160,16 @@ def open_completions(self, args):
159160
complete, mode, wantwin)
160161

161162
def fetch_completions(self, what, mode):
162-
"""Return a pair of lists of completions for something. The first list
163-
is a sublist of the second. Both are sorted.
163+
# Return a pair of lists of completions for something. The first list
164+
# is a sublist of the second. Both are sorted.
164165

165-
If there is a Python subprocess, get the comp. list there. Otherwise,
166-
either fetch_completions() is running in the subprocess itself or it
167-
was called in an IDLE EditorWindow before any script had been run.
166+
# If there is a Python subprocess, get the comp. list there. Otherwise,
167+
# either fetch_completions() is running in the subprocess itself or it
168+
# was called in an IDLE EditorWindow before any script had been run.
168169

169-
The subprocess environment is that of the most recently run script. If
170-
two unrelated modules are being edited some calltips in the current
171-
module may be inoperative if the module was not the last to run.
172-
"""
170+
# The subprocess environment is that of the most recently run script. If
171+
# two unrelated modules are being edited some calltips in the current
172+
# module may be inoperative if the module was not the last to run.
173173
try:
174174
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
175175
except:
@@ -220,7 +220,6 @@ def get_entity(self, name):
220220
"Lookup name in a namespace spanning sys.modules and __main.dict__."
221221
return eval(name, {**sys.modules, **__main__.__dict__})
222222

223-
224223
AutoComplete.reload()
225224

226225
if __name__ == '__main__':

Lib/idlelib/autocomplete_w.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
An auto-completion window for IDLE, used by the autocomplete extension
3-
"""
1+
# An auto-completion window for IDLE, used by the autocomplete extension
42
import platform
53

64
from tkinter import *
@@ -76,9 +74,8 @@ def _change_start(self, newstart):
7674
self.start = newstart
7775

7876
def _binary_search(self, s):
79-
"""Find the first index in self.completions where completions[i] is
80-
greater or equal to s, or the last index if there is no such.
81-
"""
77+
# Find the first index in self.completions where completions[i] is greater or equal to s, or the last index if there is no such.
78+
8279
i = 0; j = len(self.completions)
8380
while j > i:
8481
m = (i + j) // 2
@@ -89,10 +86,10 @@ def _binary_search(self, s):
8986
return min(i, len(self.completions)-1)
9087

9188
def _complete_string(self, s):
92-
"""Assuming that s is the prefix of a string in self.completions,
93-
return the longest string which is a prefix of all the strings which
94-
s is a prefix of them. If s is not a prefix of a string, return s.
95-
"""
89+
# Assuming that s is the prefix of a string in self.completions,
90+
# return the longest string which is a prefix of all the strings which
91+
# s is a prefix of them. If s is not a prefix of a string, return s.
92+
9693
first = self._binary_search(s)
9794
if self.completions[first][:len(s)] != s:
9895
# There is not even one completion which s is a prefix of.
@@ -121,10 +118,8 @@ def _complete_string(self, s):
121118
return first_comp[:i]
122119

123120
def _selection_changed(self):
124-
"""Call when the selection of the Listbox has changed.
121+
# Call when the selection of the Listbox has changed.Updates the Listbox display and calls _change_start.
125122

126-
Updates the Listbox display and calls _change_start.
127-
"""
128123
cursel = int(self.listbox.curselection()[0])
129124

130125
self.listbox.see(cursel)
@@ -159,11 +154,11 @@ def _selection_changed(self):
159154
self._selection_changed()
160155

161156
def show_window(self, comp_lists, index, complete, mode, userWantsWin):
162-
"""Show the autocomplete list, bind events.
157+
# Show the autocomplete list, bind events.
158+
159+
# If complete is True, complete the text, and if there is exactly
160+
# one matching completion, don't open a list.
163161

164-
If complete is True, complete the text, and if there is exactly
165-
one matching completion, don't open a list.
166-
"""
167162
# Handle the start we already have
168163
self.completions, self.morecompletions = comp_lists
169164
self.mode = mode

Lib/idlelib/browser.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
"""Module browser.
1+
#Module browser.
22

3-
XXX TO DO:
3+
# XXX TO DO:
44

5-
- reparse when source changed (maybe just a button would be OK?)
6-
(or recheck on window popup)
7-
- add popup menu with more options (e.g. doc strings, base classes, imports)
8-
- add base classes to class browser tree
9-
"""
5+
# - reparse when source changed (maybe just a button would be OK?)
6+
# (or recheck on window popup)
7+
# - add popup menu with more options (e.g. doc strings, base classes, imports)
8+
# - add base classes to class browser tree
109

1110
import os
1211
import pyclbr

Lib/idlelib/config_key.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
Dialog for building Tkinter accelerator key bindings
3-
"""
1+
# Dialog for building Tkinter accelerator key bindings
2+
43
from tkinter import Toplevel, Listbox, StringVar, TclError
54
from tkinter.ttk import Frame, Button, Checkbutton, Entry, Label, Scrollbar
65
from tkinter import messagebox
@@ -167,13 +166,12 @@ def create_widgets(self):
167166
self.toggle_level()
168167

169168
def set_modifiers_for_platform(self):
170-
"""Determine list of names of key modifiers for this platform.
169+
# Determine list of names of key modifiers for this platform.
170+
# The names are used to build Tk bindings -- it doesn't matter if the
171+
# keyboard has these keys; it matters if Tk understands them. The
172+
# order is also important: key binding equality depends on it, so
173+
# config-keys.def must use the same ordering.
171174

172-
The names are used to build Tk bindings -- it doesn't matter if the
173-
keyboard has these keys; it matters if Tk understands them. The
174-
order is also important: key binding equality depends on it, so
175-
config-keys.def must use the same ordering.
176-
"""
177175
if sys.platform == "darwin":
178176
self.modifiers = ['Shift', 'Control', 'Option', 'Command']
179177
else:

0 commit comments

Comments
 (0)