X Tutup
Skip to content

Commit 8d12b49

Browse files
committed
Matchsorting for #62
1 parent 61deda0 commit 8d12b49

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

bpython/repl.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ def complete(self, tab=False):
518518
return False
519519
else:
520520
# remove duplicates and restore order
521-
self.matches = sorted(set(matches))
521+
self.matches = sorted(set(matches), self.cmp_matches,
522+
self.key_matches)
522523

523524
if len(self.matches) == 1 and not OPTS.auto_display_list:
524525
self.list_win_visible = True
@@ -528,6 +529,19 @@ def complete(self, tab=False):
528529
self.matches_iter.update(cw, self.matches)
529530
return True
530531

532+
@staticmethod
533+
def cmp_matches(a, b):
534+
if a.startswith(('__', '_')) and not b.startswith(('__', '_')):
535+
return 1
536+
elif b.startswith(('__', '_')) and not a.startswith(('__', '_')):
537+
return -1
538+
else:
539+
return cmp(a, b)
540+
541+
@staticmethod
542+
def key_matches(name):
543+
return name.rsplit('.')[-1]
544+
531545
def format_docstring(self, docstring, width, height):
532546
"""Take a string and try to format it into a sane list of strings to be
533547
put into the suggestion box."""

0 commit comments

Comments
 (0)
X Tutup