@@ -162,6 +162,8 @@ def from_string(cls, value):
162162
163163
164164def after_last_dot (name ):
165+ """matches are stored as 'math.cos', 'math.sin', etc. This function returns
166+ just 'cos' or 'sin' """
165167 return name .rstrip ("." ).rsplit ("." )[- 1 ]
166168
167169
@@ -213,7 +215,9 @@ def __init__(self, shown_before_tab=True, mode=AutocompleteModes.SIMPLE):
213215
214216 def matches (self , cursor_offset , line , ** kwargs ):
215217 """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.
217221
218222 ie, import completion doesn't make sense if there cursor isn't after
219223 an import or from statement, so it ought to return None.
@@ -413,7 +417,12 @@ def attr_lookup(self, obj, expr, attr):
413417 n = len (attr )
414418 for word in words :
415419 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 ))
417426 return matches
418427
419428 def list_attributes (self , obj ):
@@ -690,6 +699,6 @@ def get_default_completer(mode=AutocompleteModes.SIMPLE, module_gatherer=None):
690699
691700def _callable_postfix (value , word ):
692701 """rlcompleter's _callable_postfix done right."""
693- if callable (value ):
694- word += "("
702+ if inspection . is_callable (value ):
703+ word += "() "
695704 return word
0 commit comments