-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Idlelib.browser: stop sorting dicts created by pyclbr #76592
Comments
pyclbr does a linear scan of a file and returns a dict, and Class objects have a dict of children. For objects in the file being scanned, insertion order is the same as line number order. idlelib.browser.transform children filters out objects not in the file, changes the .name of some objects in the file, appends to a list, and sorts by line number. (I should have done the sort in place.) For insertion order dicts, the sort does nothing. In 3.7, insertion order is a language guarantee, not just a (current) CPython implementation detail. The sort does not change the order and is therefore no longer needed. We can reduce However, I do want to make sure that there is at least one test that will break if there is a bug somewhere. |
Terry, In test_browser, would it be a good test if mock_pyclbr_tree was created as The reason that I'm asking is that, under 2.7 and 3.3, this dictionary does not retain the insertion order, but changes it from (C0, f0) to (f0, C0). Or did you just want a test that checks that the line numbers are still in order when the code is returned from transform_children? |
(f0, C0) is the correct insertion and line number order for the dict that would be returned by pyclbr for a fleshed-out file. After 'sorted' is removed, the mock must imitate that. One could argue that previously, and even now for 3.6, the initial insertion order should be 'wrong' to test that format_children sorts the return list. But what is the chance that there will ever be an alternate 3.6 (or even later) implementation that runs tkinter and therefore might run IDLE but has a dict that does not preserve insert order? I probably should not worry about the dict insert order guarantee being rescinded in a future version. Maybe instead I should just add a comment that transform_children depends on iteration order being insert order == line-number order. |
Terry, I'm not sure if I phrased my initial question correctly. I've made a pull request to show you what I was thinking. What I had tried to show with the test case change is that, prior to the guarantee of insertion order on the dictionary, the check Thanks! |
The patch is trivial, and I assume that the test change is adequate, but I want to put this issue on hold for the present because 'The present' ends when 3.6 maintenance ends in 6 months or at least the module browser is patched, whichever is first. |
I should mention that using Treeview could mean not using pyclbr. Instead, we might extract the parsing loop and modify it to build tree nodes as functions and classes are encountered. |
Can this move forward now? |
yes ;-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: