Skip to content
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

Merged
merged 3 commits into from
Jun 27, 2017
Merged

Conversation

csabella
Copy link
Contributor

No description provided.

Copy link
Contributor

@mlouielu mlouielu left a 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.

class GrepDialog(SearchDialogBase):
"Search Dialog for Find in Files."
Copy link
Contributor

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."""

Copy link
Member

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."?


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Create search dialog for ...

Copy link
Member

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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Make dialog visible .... """

Copy link
Member

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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Create base entry .... path."""

Copy link
Member

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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Add check button ....subdirectories."""

Copy link
Member

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."
Copy link
Contributor

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."""

prog = self.engine.getprog()
if not prog:
return
return None
Copy link
Contributor

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

Copy link
Member

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.

if self.top:
self.top.grab_release()
self.top.withdraw()
"Close the dialog."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Close the dialog."""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

@mlouielu
Copy link
Contributor

I also create a picture for the import relationship for IDLE. you can saw it here:

@csabella
Copy link
Contributor Author

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.

class GrepDialog(SearchDialogBase):
"Search Dialog for Find in Files."
Copy link
Member

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."?

@@ -1,3 +1,8 @@
"""Grep dialog for Find in File functionality.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Files', plural

Args:
text: Text widget that contains the selected text for
default search phrase.
io: IOBinding with default path to search.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'iomenu.IOBinding instance'


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.
Copy link
Member

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."
Copy link
Member

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.

"(Hint: right-click to open locations.)"
% hits) if hits else "No hits.")
"(Hint: right-click to open locations.)"
% hits) if hits else "No hits.")
Copy link
Member

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.

Copy link
Contributor Author

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.

self.top.grab_release()
self.top.withdraw()
"Close the dialog."
SearchDialogBase.close(self, event)
Copy link
Member

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.

Copy link
Contributor Author

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."
Copy link
Member

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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks.

@csabella
Copy link
Contributor Author

@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?

@mlouielu
Copy link
Contributor

@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.

@terryjreedy terryjreedy merged commit 65474b9 into python:master Jun 27, 2017
terryjreedy pushed a commit to terryjreedy/cpython that referenced this pull request Jun 27, 2017
Patch by Cheryl Sabella
(cherry picked from commit 65474b9)
terryjreedy added a commit that referenced this pull request Jun 27, 2017
Patch by Cheryl Sabella
(cherry picked from commit 65474b9)
@csabella csabella deleted the grep branch July 1, 2017 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants