Skip to content

Commit 0cc3b86

Browse files
committed
Update (unfinished) PR to present day
1 parent d07a405 commit 0cc3b86

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

bpython/autocomplete.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ def from_string(cls, value):
162162

163163

164164
def 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

691700
def _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

bpython/repl.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,13 @@ def __iter__(self):
254254
def current(self):
255255
if self.index == -1:
256256
raise ValueError("No current match.")
257-
return self.matches[self.index]
257+
cur = self.matches[self.index]
258+
return self.strip_parens(cur)
259+
260+
def strip_parens(self, word):
261+
if word.endswith("()"):
262+
word = word[:-2]
263+
return word
258264

259265
def next(self):
260266
return self.__next__()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy