IPython should prioritize __all__ during tab completion

Bug #462648 reported by Daniel Holth
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
IPython
Confirmed
Wishlist
Unassigned

Bug Description

When exploring an api with tab completion, it is sometimes useful to distinguish between the public interface (names intended for use) and the implementation (unrelated imported modules, double underscore names and so on).

IPython could help, with minimal implementation difficulty, by putting names in __all__ first during tab completion. For example,

>>> import urllib
>>> urllib.<tab>
urllib.ContentTooShortError urllib._localhost urllib.quote
urllib.FancyURLopener urllib._noheaders urllib.quote_plus
urllib.MAXFTPCACHE urllib._nportprog urllib.reporthook
urllib.URLopener urllib._passwdprog urllib.socket
urllib.__all__ urllib._portprog urllib.splitattr
urllib.__builtins__ urllib._queryprog urllib.splithost
urllib.__class__ urllib._safemaps urllib.splitnport
urllib.__delattr__ urllib._tagprog urllib.splitpasswd
urllib.__dict__ urllib._thishost urllib.splitport
urllib.__doc__ urllib._typeprog urllib.splitquery
urllib.__file__ urllib._urlopener urllib.splittag
urllib.__format__ urllib._userprog urllib.splittype
urllib.__getattribute__ urllib._valueprog urllib.splituser
urllib.__hash__ urllib.addbase urllib.splitvalue
urllib.__init__ urllib.addclosehook urllib.ssl
urllib.__name__ urllib.addinfo urllib.string
urllib.__new__ urllib.addinfourl urllib.sys
urllib.__package__ urllib.always_safe urllib.test
urllib.__reduce__ urllib.basejoin urllib.test1
urllib.__reduce_ex__ urllib.ftpcache urllib.thishost
urllib.__repr__ urllib.ftperrors urllib.time
urllib.__setattr__ urllib.ftpwrapper urllib.toBytes
urllib.__sizeof__ urllib.getproxies urllib.unquote
urllib.__str__ urllib.getproxies_environment urllib.unquote_plus
urllib.__subclasshook__ urllib.localhost urllib.unwrap
urllib.__version__ urllib.main urllib.url2pathname
urllib._ftperrors urllib.noheaders urllib.urlcleanup
urllib._have_ssl urllib.os urllib.urlencode
urllib._hextochr urllib.pathname2url urllib.urlopen
urllib._hostprog urllib.proxy_bypass urllib.urlretrieve
urllib._is_unicode urllib.proxy_bypass_environment urllib.warnings

If I'm using the library, I don't care that urllib.py imports 'os'. Instead, why not show something more like:

>>> urllib.<tab>
__all__: ['urlopen', 'URLopener', 'FancyURLopener', 'urlretrieve', 'urlcleanup', 'quote', 'quote_plus', 'unquote', 'unquote_plus', 'urlencode', 'url2pathname', 'pathname2url', 'splittag', 'localhost', 'thishost', 'ftperrors', 'basejoin', 'unwrap', 'splittype', 'splithost', 'splituser', 'splitpasswd', 'splitport', 'splitnport', 'splitquery', 'splitattr', 'splitvalue', 'getproxies']

everything else, or everything including __all__ names:
(from above)

Revision history for this message
Fernando Perez (fdo.perez) wrote :

Unfortunately I don't think that's possible, at least with readline. Readline uses a callback interface and expects only a list of completions. The printing/formatting of the completions is done by readline, not by us, and in a list there is no way of specifying what comes from where.

This would be possible, and it's a good idea, for more sophisticated guis that manage their own completion. I'm marking it as a wishlist so we keep it in mind moving forward, though at the terminal I'm afraid we're limited by readline's design.

Thanks for the idea.

Changed in ipython:
status: New → Confirmed
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.