[Python-checkins] r64664 - in python/trunk: Doc/library/rlcompleter.rst Lib/rlcompleter.py Misc/NEWS

facundo.batista python-checkins at python.org
Wed Jul 2 18:52:56 CEST 2008


Author: facundo.batista
Date: Wed Jul  2 18:52:55 2008
New Revision: 64664

Log:

Issue #449227: Now with the rlcompleter module, callable objects are
added a '(' when completed.


Modified:
   python/trunk/Doc/library/rlcompleter.rst
   python/trunk/Lib/rlcompleter.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Doc/library/rlcompleter.rst
==============================================================================
--- python/trunk/Doc/library/rlcompleter.rst	(original)
+++ python/trunk/Doc/library/rlcompleter.rst	Wed Jul  2 18:52:55 2008
@@ -20,9 +20,9 @@
    >>> import readline
    >>> readline.parse_and_bind("tab: complete")
    >>> readline. <TAB PRESSED>
-   readline.__doc__          readline.get_line_buffer  readline.read_init_file
-   readline.__file__         readline.insert_text      readline.set_completer
-   readline.__name__         readline.parse_and_bind
+   readline.__doc__          readline.get_line_buffer(  readline.read_init_file(
+   readline.__file__         readline.insert_text(      readline.set_completer(
+   readline.__name__         readline.parse_and_bind(
    >>> readline.
 
 The :mod:`rlcompleter` module is designed for use with Python's interactive

Modified: python/trunk/Lib/rlcompleter.py
==============================================================================
--- python/trunk/Lib/rlcompleter.py	(original)
+++ python/trunk/Lib/rlcompleter.py	Wed Jul  2 18:52:55 2008
@@ -92,6 +92,11 @@
         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 @@
         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 @@
         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):

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Jul  2 18:52:55 2008
@@ -33,6 +33,9 @@
 Library
 -------
 
+- Issue #449227: Now with the rlcompleter module, callable objects are added
+  "(" when completed.
+
 - Issue #3190: Pydoc now hides the automatic module attribute __package__ (the
   handling is now the same as that of other special attributes like __name__).
 


More information about the Python-checkins mailing list