-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Conversation
@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. |
The first commit is almost exactly the original patch, with the differences being that |
50410ae
to
61be9ae
Compare
63193a4
to
050975a
Compare
A fix for the busted news entry check is coming shortly. |
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. |
OK, the news status issue is all fixed. Sorry about that. 😞 |
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 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.
Lib/idlelib/browser.py
Outdated
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). |
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 docstring says nothing about the name parameter.
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'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.
Lib/idlelib/browser.py
Outdated
""" | ||
items = [] | ||
children = {} | ||
for key, cl in node.items(): |
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 'cl' can be either a class or function object. 'c_f' or 'obj' would be a clearer name.
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.
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.
Lib/idlelib/browser.py
Outdated
children = {} | ||
for key, cl in node.items(): | ||
if name is None or cl.module == name: | ||
s = key |
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.
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.
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 wasn't sure how much you wanted to refactor before knowing the tests were good.
Lib/idlelib/browser.py
Outdated
children[s] = cl | ||
return children, items | ||
|
||
|
||
class ClassBrowser: |
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.
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.
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.
Did you want the change to ModuleBrowser to happen before this current PR?
af601aa
to
2992dfb
Compare
@@ -0,0 +1,236 @@ | |||
""" Test idlelib.browser. | |||
""" |
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 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.
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. |
Thanks @csabella for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
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. |
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. |
Original patch by Guilherme Polo.
https://bugs.python.org/issue1612262