Open
Description
IPython.utils.io
has stdin, stdout and stderr attributes which wrap the corresponding stream objects from sys
in an IOStream
instance. Then certain odd places around the codebase, such as oinspect, do print(..., file=io.stdout)
, while other places don't.
I assume that this was originally supposed to provide an indirection layer so stdout/stderr could easily be redirected. However:
- Things that redirect stdout/stderr typically replace them directly in
sys
- they have to, because not all printing is directed through theIPython.utils.io
objects. There are backup copies of the original objects as e.g.sys.__stdout__
, so replacingsys.stdout
is not destructive. - When
sys.std*
is replaced,io.std*
still has a reference to the originalsys.std*
objects, so it doesn't respect the redirection. See issue Support changing sys.std* streams #8669, and I also just ran into this trying to use colorama in Terminal interface based on prompt_toolkit #9118.
I'm proposing that we deprecate io.std*
, and move all uses of it in our own code to sys.std*
. Does anyone know of a reason not to do this?
Ping @fperez, because I'm pretty sure this code has been around longer than I've been on the project.