IPython should prioritize __all__ during tab completion
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.
urllib.
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.
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.
urllib.__repr__ urllib.ftperrors urllib.time
urllib.__setattr__ urllib.ftpwrapper urllib.toBytes
urllib.__sizeof__ urllib.getproxies urllib.unquote
urllib.__str__ urllib.
urllib.
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.
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)
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.