@@ -162,6 +162,8 @@ def from_string(cls, value):
162
162
163
163
164
164
def after_last_dot (name ):
165
+ """matches are stored as 'math.cos', 'math.sin', etc. This function returns
166
+ just 'cos' or 'sin' """
165
167
return name .rstrip ("." ).rsplit ("." )[- 1 ]
166
168
167
169
@@ -213,7 +215,9 @@ def __init__(self, shown_before_tab=True, mode=AutocompleteModes.SIMPLE):
213
215
214
216
def matches (self , cursor_offset , line , ** kwargs ):
215
217
"""Returns a list of possible matches given a line and cursor, or None
216
- if this completion type isn't applicable.
218
+ if this completion type isn't applicable. Callable matches will end
219
+ with open close parens "()", but when they are replaced, parens are
220
+ removed.
217
221
218
222
ie, import completion doesn't make sense if there cursor isn't after
219
223
an import or from statement, so it ought to return None.
@@ -413,7 +417,12 @@ def attr_lookup(self, obj, expr, attr):
413
417
n = len (attr )
414
418
for word in words :
415
419
if self .method_match (word , n , attr ) and word != "__builtins__" :
416
- matches .append (f"{ expr } .{ word } " )
420
+ try :
421
+ if callable (inspection .getattr_safe (obj , word )):
422
+ word += "()"
423
+ except AttributeError :
424
+ pass
425
+ matches .append ("%s.%s" % (expr , word ))
417
426
return matches
418
427
419
428
def list_attributes (self , obj ):
@@ -690,6 +699,6 @@ def get_default_completer(mode=AutocompleteModes.SIMPLE, module_gatherer=None):
690
699
691
700
def _callable_postfix (value , word ):
692
701
"""rlcompleter's _callable_postfix done right."""
693
- if callable (value ):
694
- word += "("
702
+ if inspection . is_callable (value ):
703
+ word += "() "
695
704
return word
0 commit comments