When an object has hundreds of methods, tab completion is hard to use. More often than not the interesting methods are the ones defined or overridden by the inspected object's class and not its base classes.
How can I get IPython to group its tab completion possibilities so the methods and properties defined in the inspected object's class come first, followed by those in base classes?
It looks like the undocumented inspect.classify_class_attrs(cls)
function along with inspect.getmro(cls)
give me most of the information I need (these were originally written to implement python's help(object)
feature).
By default readline displays completions alphabetically, but the function used to display completions can be replaced with ctypes or the readline module included with Python 2.6 and above. I've overridden readline's completions display and it works great.
Now all I need is a method to merge per-class information (from inspect.*
per above) with per-instance information, sort the results by method resolution order, pretty print and paginate.
For extra credit, it would be great to store the chosen autocompletion, and display the most popular choices first next time autocomplete is attempted on the same object.