Skip to content

Commit 1a4d9ff

Browse files
csabellaterryjreedy
authored andcommitted
bpo-32411: IDLE: Remove line number sort in browser.py (#5011)
Insertion in line order makes sorting keys by line order unneeded.
1 parent e5f6207 commit 1a4d9ff

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Released on 2019-10-20?
33
======================================
44

55

6+
bpo-32411: Stop sorting dict created with desired line order.
7+
68
bpo-37038: Make idlelib.run runnable; add test clause.
79

810
bpo-36958: Print any argument other than None or int passed to

Lib/idlelib/browser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def transform_children(child_dict, modname=None):
2929
The dictionary maps names to pyclbr information objects.
3030
Filter out imported objects.
3131
Augment class names with bases.
32-
Sort objects by line number.
32+
The insertion order of the dictonary is assumed to have been in line
33+
number order, so sorting is not necessary.
3334
34-
The current tree only calls this once per child_dic as it saves
35+
The current tree only calls this once per child_dict as it saves
3536
TreeItems once created. A future tree and tests might violate this,
3637
so a check prevents multiple in-place augmentations.
3738
"""
@@ -51,7 +52,7 @@ def transform_children(child_dict, modname=None):
5152
supers.append(sname)
5253
obj.name += '({})'.format(', '.join(supers))
5354
obs.append(obj)
54-
return sorted(obs, key=lambda o: o.lineno)
55+
return obs
5556

5657

5758
class ModuleBrowser:

Lib/idlelib/idle_test/test_browser.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ def test_close(self):
6161
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
6262
mb = pyclbr
6363
module, fname = 'test', 'test.py'
64-
f0 = mb.Function(module, 'f0', fname, 1)
65-
f1 = mb._nest_function(f0, 'f1', 2)
66-
f2 = mb._nest_function(f1, 'f2', 3)
67-
c1 = mb._nest_class(f0, 'c1', 5)
68-
C0 = mb.Class(module, 'C0', ['base'], fname, 6)
69-
F1 = mb._nest_function(C0, 'F1', 8)
70-
C1 = mb._nest_class(C0, 'C1', 11, [''])
71-
C2 = mb._nest_class(C1, 'C2', 12)
72-
F3 = mb._nest_function(C2, 'F3', 14)
73-
mock_pyclbr_tree = {'f0': f0, 'C0': C0}
64+
C0 = mb.Class(module, 'C0', ['base'], fname, 1)
65+
F1 = mb._nest_function(C0, 'F1', 3)
66+
C1 = mb._nest_class(C0, 'C1', 6, [''])
67+
C2 = mb._nest_class(C1, 'C2', 7)
68+
F3 = mb._nest_function(C2, 'F3', 9)
69+
f0 = mb.Function(module, 'f0', fname, 11)
70+
f1 = mb._nest_function(f0, 'f1', 12)
71+
f2 = mb._nest_function(f1, 'f2', 13)
72+
c1 = mb._nest_class(f0, 'c1', 15)
73+
mock_pyclbr_tree = {'C0': C0, 'f0': f0}
7474

7575
# Adjust C0.name, C1.name so tests do not depend on order.
7676
browser.transform_children(mock_pyclbr_tree, 'test') # C0(base)
@@ -87,12 +87,12 @@ def test_transform_module_children(self):
8787
transform = browser.transform_children
8888
# Parameter matches tree module.
8989
tcl = list(transform(mock_pyclbr_tree, 'test'))
90-
eq(tcl, [f0, C0])
91-
eq(tcl[0].name, 'f0')
92-
eq(tcl[1].name, 'C0(base)')
90+
eq(tcl, [C0, f0])
91+
eq(tcl[0].name, 'C0(base)')
92+
eq(tcl[1].name, 'f0')
9393
# Check that second call does not change suffix.
9494
tcl = list(transform(mock_pyclbr_tree, 'test'))
95-
eq(tcl[1].name, 'C0(base)')
95+
eq(tcl[0].name, 'C0(base)')
9696
# Nothing to traverse if parameter name isn't same as tree module.
9797
tcl = list(transform(mock_pyclbr_tree, 'different name'))
9898
eq(tcl, [])
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In browser.py, remove extraneous sorting by line number since dictionary was
2+
created in line number order.

0 commit comments

Comments
 (0)