Comment 1 for bug 319620

Revision history for this message
Daniel Holth (dholth) wrote :

The undocumented inspect.classify_class_attrs(cls) function, along with inspect.getmro(cls) give most of the information needed to implement this feature.

By default readline displays completions alphabetically, but the function used to display completions can be replaced using ctypes or the readline module included with Python 2.6 and above. The completion_display_matches_hook function could hold a reference to the completer which would provide the last autocompleted object.

Example of problem:

In [30]: portal.<tab>
Display all 919 possibilities? (y or n)

How to override the completion_display_matches_hook in Pythons earlier than Python 2.6:

from ctypes import *

rl = cdll.LoadLibrary('libreadline.so')

def completion_display_func(matches, num_matches, max_length):
    print "made you look"

COMPLETION_DISPLAY_FUNC = CFUNCTYPE(None, POINTER(c_char_p), c_int, c_int)
hook = COMPLETION_DISPLAY_FUNC(completion_display_func)
ptr = c_void_p.in_dll(rl, 'rl_completion_display_matches_hook')
ptr.value = cast(hook, c_void_p).value