These are chat archives for ipython/ipython

May 2018
Alain Kalker
May 13 2018 16:55

Hi all, I wonder why ipython (using Python 3.6.5) tab completion completes some attributes but not others:

In [1]: import sys

In [2]: sys.stdout.<TAB>
                    sys.stdout.encoding sys.stdout.flush    
                    sys.stdout.errors   sys.stdout.write

I know that there are other (public) attributes from dir(sys.stdout) and because one has to use sys.stdout.buffer.write() to write binary data to standard output.

Is there a way to 'hide' certain attributes from tab completion in my own classes?

Alain Kalker
May 13 2018 17:01
I know about implementing my own MyClass.__dir__() from the docs, but oddly (for me that is), it appears that the _io.TextIOWrapper built-in class for sys.stdout uses the default implementation for __dir__(), so I guess it isn't using this particular trick.