@@ -256,6 +256,7 @@ def matches(self, cursor_offset, line, **kwargs):
256
256
if not r .word .split ('.' )[- 1 ].startswith ('_' ):
257
257
matches = set (match for match in matches
258
258
if not match .split ('.' )[- 1 ].startswith ('_' ))
259
+ # MAYBE HERE 2 ??
259
260
return matches
260
261
261
262
def locate (self , current_offset , line ):
@@ -311,6 +312,8 @@ def attr_lookup(self, obj, expr, attr):
311
312
for word in words :
312
313
if self .method_match (word , n , attr ) and word != "__builtins__" :
313
314
matches .append ("%s.%s" % (expr , word ))
315
+ # print 'matches', matches
316
+ # ORGANIZE THE THINGS HERE MAYBE 1??
314
317
return matches
315
318
316
319
if py3 :
@@ -543,13 +546,31 @@ def get_completer(completers, cursor_offset, line, **kwargs):
543
546
complete_magic_methods is a bool of whether we ought to complete
544
547
double underscore methods like __len__ in method signatures
545
548
"""
546
-
547
549
for completer in completers :
548
550
matches = completer .matches (cursor_offset , line , ** kwargs )
549
551
if matches is not None :
550
- return sorted (matches ), (completer if matches else None )
552
+ if len (matches ) > 0 :
553
+ matches = sort_by_underscore (matches )
554
+ return matches , (completer if matches else None )
551
555
return [], None
552
556
557
+ def sort_by_underscore (matches ):
558
+ """Sort single underscore attributes before double underscore ones.
559
+ """
560
+ matches = sorted (matches )
561
+ if len (matches ) == 0 or len (matches ) == 1 :
562
+ return matches
563
+ one_underscore = None
564
+ for i in xrange (1 , len (matches )+ 1 ):
565
+ i = - i
566
+ dot_i = matches [i ].rfind ('.' ) + 1
567
+ if matches [i ][dot_i ] == '_' and matches [i ][dot_i + 1 ] != '_' :
568
+ one_underscore = i
569
+ else :
570
+ break
571
+ if one_underscore_i != None :
572
+ return matches [one_underscore :] + matches [:one_underscore ]
573
+ return matches
553
574
554
575
def get_default_completer (mode = SIMPLE ):
555
576
return (
0 commit comments