Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature: Add open close parentheses for attribute suggestions that are methods#840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rybarczykj wants to merge1 commit intobpython:main
base:main
Choose a base branch
Loading
fromrybarczykj:complete
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletionsbpython/autocomplete.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -162,6 +162,8 @@ def from_string(cls, value):


def after_last_dot(name):
"""matches are stored as 'math.cos', 'math.sin', etc. This function returns
just 'cos' or 'sin' """
return name.rstrip(".").rsplit(".")[-1]


Expand DownExpand Up@@ -213,7 +215,9 @@ def __init__(self, shown_before_tab=True, mode=AutocompleteModes.SIMPLE):

def matches(self, cursor_offset, line, **kwargs):
"""Returns a list of possible matches given a line and cursor, or None
if this completion type isn't applicable.
if this completion type isn't applicable. Callable matches will end
with open close parens "()", but when they are replaced, parens are
removed.

ie, import completion doesn't make sense if there cursor isn't after
an import or from statement, so it ought to return None.
Expand DownExpand Up@@ -413,7 +417,12 @@ def attr_lookup(self, obj, expr, attr):
n = len(attr)
for word in words:
if self.method_match(word, n, attr) and word != "__builtins__":
matches.append(f"{expr}.{word}")
try:
if callable(inspection.getattr_safe(obj, word)):
word += "()"
except AttributeError:
pass
matches.append("%s.%s" % (expr, word))
return matches

def list_attributes(self, obj):
Expand DownExpand Up@@ -690,6 +699,6 @@ def get_default_completer(mode=AutocompleteModes.SIMPLE, module_gatherer=None):

def _callable_postfix(value, word):
"""rlcompleter's _callable_postfix done right."""
ifcallable(value):
word += "("
ifinspection.is_callable(value):
word += "()"
return word
8 changes: 7 additions & 1 deletionbpython/repl.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,7 +254,13 @@ def __iter__(self):
def current(self):
if self.index == -1:
raise ValueError("No current match.")
return self.matches[self.index]
cur = self.matches[self.index]
return self.strip_parens(cur)

def strip_parens(self, word):
if word.endswith("()"):
word = word[:-2]
return word

def next(self):
return self.__next__()
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp