-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-30674: IDLE: add docstrings to grep.py #2213
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, some small point should be changed.
Lib/idlelib/grep.py
Outdated
class GrepDialog(SearchDialogBase): | ||
"Search Dialog for Find in Files." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Search dialog for find in files."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The menu item is 'Find in Files', but I agree it is not obvious and awkward if one does not notice. "Find in Files" is already in file docstring. How about "Dialog for searching multiple files."?
Lib/idlelib/grep.py
Outdated
|
||
title = "Find in Files Dialog" | ||
icon = "Grep" | ||
needwrapbutton = 0 | ||
|
||
def __init__(self, root, engine, flist): | ||
"""Create Search Dialog for searching for a phrase in the file system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Create search dialog for ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
SearchDialogBase.__init__(self, root, engine) | ||
self.flist = flist | ||
self.globvar = StringVar(root) | ||
self.recvar = BooleanVar(root) | ||
|
||
def open(self, text, searchphrase, io=None): | ||
"Make dialog visible on top of others and ready to use." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Make dialog visible .... """
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Single double quote is allowed and preferred by me. Common in stdlib.
@@ -45,36 +73,54 @@ def open(self, text, searchphrase, io=None): | |||
self.globvar.set(os.path.join(dir, "*" + tail)) | |||
|
|||
def create_entries(self): | |||
"Create base entry widgets and add widget for search path." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Create base entry .... path."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
SearchDialogBase.create_entries(self) | ||
self.globent = self.make_entry("In files:", self.globvar)[0] | ||
|
||
def create_other_buttons(self): | ||
"Add check button to recurse down subdirectories." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Add check button ....subdirectories."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
btn = Checkbutton( | ||
self.make_frame()[0], variable=self.recvar, | ||
text="Recurse down subdirectories") | ||
btn.pack(side="top", fill="both") | ||
|
||
def create_command_buttons(self): | ||
"Create base command buttons and add button for search." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Create base command .... for search."""
Lib/idlelib/grep.py
Outdated
prog = self.engine.getprog() | ||
if not prog: | ||
return | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
will return None
. So you don't need to explicit return None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Either all return statements in a function should return an expression, or none of them should." So if any must (return an expression), all must, but if all return None, then none must, so None can be omitted but must be omitted everywhere.
Lib/idlelib/grep.py
Outdated
if self.top: | ||
self.top.grab_release() | ||
self.top.withdraw() | ||
"Close the dialog." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Close the dialog."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
Terry had changed my """ quotes on a previous PR to just " when the docstring was only one line. I was following his convention with these changes. |
Lib/idlelib/grep.py
Outdated
class GrepDialog(SearchDialogBase): | ||
"Search Dialog for Find in Files." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The menu item is 'Find in Files', but I agree it is not obvious and awkward if one does not notice. "Find in Files" is already in file docstring. How about "Dialog for searching multiple files."?
Lib/idlelib/grep.py
Outdated
@@ -1,3 +1,8 @@ | |||
"""Grep dialog for Find in File functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Files', plural
Lib/idlelib/grep.py
Outdated
Args: | ||
text: Text widget that contains the selected text for | ||
default search phrase. | ||
io: IOBinding with default path to search. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'iomenu.IOBinding instance'
Lib/idlelib/grep.py
Outdated
|
||
title = "Find in Files Dialog" | ||
icon = "Grep" | ||
needwrapbutton = 0 | ||
|
||
def __init__(self, root, engine, flist): | ||
"""Create Search Dialog for searching for a phrase in the file system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
SearchDialogBase.__init__(self, root, engine) | ||
self.flist = flist | ||
self.globvar = StringVar(root) | ||
self.recvar = BooleanVar(root) | ||
|
||
def open(self, text, searchphrase, io=None): | ||
"Make dialog visible on top of others and ready to use." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Single double quote is allowed and preferred by me. Common in stdlib.
Lib/idlelib/grep.py
Outdated
"(Hint: right-click to open locations.)" | ||
% hits) if hits else "No hits.") | ||
"(Hint: right-click to open locations.)" | ||
% hits) if hits else "No hits.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was technically correct as it was, but it looks better with the extra space. But I don't really like it either way (and I wrote it in this form). In 3.6+, we can do
print(f"Hits found: {hits}\n"
f"(Hint: right-click to open locations.)"
if hits else "No hits.")
# or with 79 char lines
print(f"Hits found: {hits}\n(Hint: right-click to open locations.)"
if hits else "No hits.")
I like both of these better, so choose one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. I also changed the other string formatting lines to use f strings.
Lib/idlelib/grep.py
Outdated
self.top.grab_release() | ||
self.top.withdraw() | ||
"Close the dialog." | ||
SearchDialogBase.close(self, event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Maybe these were once different. Now, just delete GrepDialog.close and inherit SearchDialogBase.close.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -45,36 +73,54 @@ def open(self, text, searchphrase, io=None): | |||
self.globvar.set(os.path.join(dir, "*" + tail)) | |||
|
|||
def create_entries(self): | |||
"Create base entry widgets and add widget for search path." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
SearchDialogBase.create_entries(self) | ||
self.globent = self.make_entry("In files:", self.globvar)[0] | ||
|
||
def create_other_buttons(self): | ||
"Add check button to recurse down subdirectories." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Lib/idlelib/grep.py
Outdated
from idlelib.outwin import OutputWindow # leave here! | ||
save = sys.stdout | ||
try: | ||
sys.stdout = OutputWindow(self.flist) | ||
self.grep_it(prog, path) | ||
finally: | ||
sys.stdout = save | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None " So if no return statement return an expression, no explicit return is needed at the end. In other words, this function was within the rules and should be left as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks.
@mlouielu @terryjreedy Thanks for the reviews. I added an additional note to default_command to mention that the search dialog is closed when the search begins. One other question -- when I run this, the dialog box always opens way on the bottom of my screen. Has anyone requested a change to this before? Or would it be worth mentioning on idle-dev? |
@csabella I think your question should also post it on b.p.o. Since here is to discuss about code review. I didn't get this on macOS, the dialog show off at the left top side of the screen. |
Patch by Cheryl Sabella (cherry picked from commit 65474b9)
No description provided.