summaryrefslogtreecommitdiff
path: root/Lib/rlcompleter.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-07-02 16:52:55 +0000
committerFacundo Batista <facundobatista@gmail.com>2008-07-02 16:52:55 +0000
commitf08ec4cba01ca2141fd16e4c5694bc80d6e4c858 (patch)
tree2628cd2662feb3895c575c94d8005f7409c284ce /Lib/rlcompleter.py
parentcbe8dec331a0a57c045a97c4dc950108abbd0a72 (diff)
downloadcpython-f08ec4cba01ca2141fd16e4c5694bc80d6e4c858.tar.gz
Issue #449227: Now with the rlcompleter module, callable objects are
added a '(' when completed.
Diffstat (limited to 'Lib/rlcompleter.py')
-rw-r--r--Lib/rlcompleter.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py
index 36965e6eec..a08b825708 100644
--- a/Lib/rlcompleter.py
+++ b/Lib/rlcompleter.py
@@ -92,6 +92,11 @@ class Completer:
except IndexError:
return None
+ def _callable_postfix(self, val, word):
+ if callable(val):
+ word = word + "("
+ return word
+
def global_matches(self, text):
"""Compute matches when text is a simple name.
@@ -102,12 +107,13 @@ class Completer:
import keyword
matches = []
n = len(text)
- for list in [keyword.kwlist,
- __builtin__.__dict__,
- self.namespace]:
- for word in list:
+ for word in keyword.kwlist:
+ if word[:n] == text:
+ matches.append(word)
+ for nspace in [__builtin__.__dict__, self.namespace]:
+ for word, val in nspace.items():
if word[:n] == text and word != "__builtins__":
- matches.append(word)
+ matches.append(self._callable_postfix(val, word))
return matches
def attr_matches(self, text):
@@ -139,7 +145,9 @@ class Completer:
n = len(attr)
for word in words:
if word[:n] == attr and word != "__builtins__":
- matches.append("%s.%s" % (expr, word))
+ val = getattr(object, word)
+ word = self._callable_postfix(val, "%s.%s" % (expr, word))
+ matches.append(word)
return matches
def get_class_members(klass):