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-1612262: IDLE: Class Browser shows nested functions and classes #2573

Merged
merged 21 commits into from
Sep 22, 2017

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Jul 4, 2017

Original patch by Guilherme Polo.

https://bugs.python.org/issue1612262

@mention-bot
Copy link

@csabella, thanks for your PR! By analyzing the history of the files in this pull request, we identified @terryjreedy, @kbkaiser and @rhettinger to be potential reviewers.

@csabella
Copy link
Contributor Author

csabella commented Jul 4, 2017

The first commit is almost exactly the original patch, with the differences being that objects are now children and dict is tree. Terry, I thought you might like to see it before I added anything else, such as docstrings.

@brettcannon
Copy link
Member

A fix for the busted news entry check is coming shortly.

@brettcannon
Copy link
Member

I should also mention that if you want to merge this now then you can either add the "skip news" label or just simply ignore the failure (it isn't a required one and so you can still merge even with it failing). Otherwise if you wait 10 minutes then (hopefully) the PR I just submitted will be live and fix this.

@brettcannon
Copy link
Member

OK, the news status issue is all fixed. Sorry about that. 😞

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

I have not looked at tests yet. This works with configdialog, which has a class with a function with a function.

I experienced 1 glitch that I cannot reproduce. When I clicked on is_int, the function name in the browser changed to a methold of one of the classes. When I clicked elsewhere, it changed back.

Node is the current node being traversed. The return value is
a tuple with the first value being a dictionary of the
Class/Function instances of the node and the second is
a list of tuples with (lineno, name).
Copy link
Member

Choose a reason for hiding this comment

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

The docstring says nothing about the name parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the docstring. I think he left name as a parameter because it was used it in existing code. Also, the values returned from this function are pretty confusing. I think he tried to pull it "as-is" out of the existing code and modify it as little as possible, but it's not very clear.

"""
items = []
children = {}
for key, cl in node.items():
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 'cl' can be either a class or function object. 'c_f' or 'obj' would be a clearer name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this and the s were in the original code (as was the name key). I figured once the tests looked good, then another PR would be used to re-write the traversal code.

children = {}
for key, cl in node.items():
if name is None or cl.module == name:
s = key
Copy link
Member

Choose a reason for hiding this comment

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

Abbreviating 'key' as 's' seems pointless and confusing. (I know, you copied it.) Unless you see something I don't, delete and use 'key' below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure how much you wanted to refactor before knowing the tests were good.

children[s] = cl
return children, items


class ClassBrowser:
Copy link
Member

Choose a reason for hiding this comment

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

This should become ModuleBrowser here, 3 other places in file, and in pathbrowser. 'Class Browser' should also be change in mainmenu. We should do this in a separate issue and patch. Lets see if we can do this quickly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you want the change to ModuleBrowser to happen before this current PR?

@@ -0,0 +1,236 @@
""" Test idlelib.browser.
"""
Copy link
Member

@terryjreedy terryjreedy Sep 22, 2017

Choose a reason for hiding this comment

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

I should add coverage. 100% requires a mock that raises specific exception. I know mock_idle.Func can and presume the unittest mock can also.

I also want to revise blurb slightly.

@python python deleted a comment from bedevere-bot Sep 22, 2017
@terryjreedy
Copy link
Member

Cheryl, please take a look. Pending a recheck, I think this is ready. Effective coverage is over 90% (thanks) and remainder is not related to this issue. There are about 4 little patches to follow.

@terryjreedy terryjreedy changed the title bpo-1612262: IDLE: Class Browser for nested functions/classes bpo-1612262: IDLE: Class Browser shows nested functions and classes Sep 22, 2017
@terryjreedy terryjreedy merged commit 058de11 into python:master Sep 22, 2017
@miss-islington
Copy link
Contributor

Thanks @csabella for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@csabella
Copy link
Contributor Author

csabella commented Sep 22, 2017

Sorry, was just looking when you merged. Your changes made all the complex parts really simple. I'm glad my test didn't need too much of a rewrite. Maybe I'm getting the hang of it. :-)

One test I think I missed was making sure it sorted by line numbers.

terryjreedy added a commit to terryjreedy/cpython that referenced this pull request Sep 22, 2017
…hon#2573)

Original patches for code and tests by Guilherme Polo and
Cheryl Sabella, respectively.

(cherry picked from commit 058de11)
@terryjreedy
Copy link
Member

Please finish looking at it, in case you see something I missed. My many commits were designed to show how I got from there to here. The hardest part was converting MethodBTI, renamed to ChildBTI but still based on the design constrained by Class.methods, to properly use the child Function and Class objects (the tree nodes) and their .children attribute.

You are getting pretty decent at the tests and your drafts are very helpful.

terryjreedy added a commit that referenced this pull request Sep 22, 2017
…es (GH-2573)  (#3702)


Original patches for code and tests by Guilherme Polo and
Cheryl Sabella, respectively.

(cherry picked from commit 058de11)
@csabella csabella deleted the bpo1612262 branch September 22, 2017 21:59
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.

7 participants