You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 the IPython.utils.io objects. There are backup copies of the original objects as e.g. sys.__stdout__, so replacing sys.stdout is not destructive.
IPython.utils.iohas stdin, stdout and stderr attributes which wrap the corresponding stream objects fromsysin anIOStreaminstance. Then certain odd places around the codebase, such as oinspect, doprint(..., 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:
sys- they have to, because not all printing is directed through theIPython.utils.ioobjects. There are backup copies of the original objects as e.g.sys.__stdout__, so replacingsys.stdoutis not destructive.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 tosys.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.