diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index b48b572..5194941 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -712,16 +712,9 @@ class InteractiveShell(SingletonConfigurable): self.object_info_string_level) def init_io(self): - # This will just use sys.stdout and sys.stderr. If you want to - # override sys.stdout and sys.stderr themselves, you need to do that - # *before* instantiating this class, because io holds onto - # references to the underlying streams. - # io.std* are deprecated, but don't show our own deprecation warnings - # during initialization of the deprecated API. - with warnings.catch_warnings(): - warnings.simplefilter('ignore', DeprecationWarning) - io.stdout = io.IOStream(sys.stdout) - io.stderr = io.IOStream(sys.stderr) + # implemented in subclasses, TerminalInteractiveShell does call + # colorama.init(). + pass def init_prompts(self): # Set system prompts, so that scripts can decide if they are running diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 5e7d95f..c4fa479 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -540,16 +540,6 @@ class TerminalInteractiveShell(InteractiveShell): import colorama colorama.init() - # For some reason we make these wrappers around stdout/stderr. - # For now, we need to reset them so all output gets coloured. - # https://github.com/ipython/ipython/issues/8669 - # io.std* are deprecated, but don't show our own deprecation warnings - # during initialization of the deprecated API. - with warnings.catch_warnings(): - warnings.simplefilter('ignore', DeprecationWarning) - io.stdout = io.IOStream(sys.stdout) - io.stderr = io.IOStream(sys.stderr) - def init_magics(self): super(TerminalInteractiveShell, self).init_magics() self.register_magics(TerminalMagics) diff --git a/IPython/testing/globalipapp.py b/IPython/testing/globalipapp.py index c58d575..698e3d8 100644 --- a/IPython/testing/globalipapp.py +++ b/IPython/testing/globalipapp.py @@ -23,30 +23,6 @@ from IPython.utils import io from IPython.terminal.interactiveshell import TerminalInteractiveShell -class StreamProxy(io.IOStream): - """Proxy for sys.stdout/err. This will request the stream *at call time* - allowing for nose's Capture plugin's redirection of sys.stdout/err. - - Parameters - ---------- - name : str - The name of the stream. This will be requested anew at every call - """ - - def __init__(self, name): - warnings.warn("StreamProxy is deprecated and unused as of IPython 5", DeprecationWarning, - stacklevel=2, - ) - self.name=name - - @property - def stream(self): - return getattr(sys, self.name) - - def flush(self): - self.stream.flush() - - def get_ipython(): # This will get replaced by the real thing once we start IPython below return start_ipython() diff --git a/IPython/utils/io.py b/IPython/utils/io.py index 638471e..69e4d4e 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -19,82 +19,10 @@ from warnings import warn from IPython.utils.decorators import undoc from .capture import CapturedIO, capture_output -@undoc -class IOStream: - - def __init__(self, stream, fallback=None): - warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', - DeprecationWarning, stacklevel=2) - if not hasattr(stream,'write') or not hasattr(stream,'flush'): - if fallback is not None: - stream = fallback - else: - raise ValueError("fallback required, but not specified") - self.stream = stream - self._swrite = stream.write - - # clone all methods not overridden: - def clone(meth): - return not hasattr(self, meth) and not meth.startswith('_') - for meth in filter(clone, dir(stream)): - try: - val = getattr(stream, meth) - except AttributeError: - pass - else: - setattr(self, meth, val) - - def __repr__(self): - cls = self.__class__ - tpl = '{mod}.{cls}({args})' - return tpl.format(mod=cls.__module__, cls=cls.__name__, args=self.stream) - - def write(self,data): - warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', - DeprecationWarning, stacklevel=2) - try: - self._swrite(data) - except: - try: - # print handles some unicode issues which may trip a plain - # write() call. Emulate write() by using an empty end - # argument. - print(data, end='', file=self.stream) - except: - # if we get here, something is seriously broken. - print('ERROR - failed to write data to stream:', self.stream, - file=sys.stderr) - - def writelines(self, lines): - warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', - DeprecationWarning, stacklevel=2) - if isinstance(lines, str): - lines = [lines] - for line in lines: - self.write(line) - - # This class used to have a writeln method, but regular files and streams - # in Python don't have this method. We need to keep this completely - # compatible so we removed it. - - @property - def closed(self): - return self.stream.closed - - def close(self): - pass - # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr devnull = open(os.devnull, 'w') atexit.register(devnull.close) -# io.std* are deprecated, but don't show our own deprecation warnings -# during initialization of the deprecated API. -with warnings.catch_warnings(): - warnings.simplefilter('ignore', DeprecationWarning) - stdin = IOStream(sys.stdin, fallback=devnull) - stdout = IOStream(sys.stdout, fallback=devnull) - stderr = IOStream(sys.stderr, fallback=devnull) class Tee(object): """A class to duplicate an output stream to stdout/err. @@ -208,12 +136,6 @@ def temp_pyfile(src, ext='.py'): f.flush() return fname -@undoc -def atomic_writing(*args, **kwargs): - """DEPRECATED: moved to notebook.services.contents.fileio""" - warn("IPython.utils.io.atomic_writing has moved to notebook.services.contents.fileio since IPython 4.0", DeprecationWarning, stacklevel=2) - from notebook.services.contents.fileio import atomic_writing - return atomic_writing(*args, **kwargs) @undoc def raw_print(*args, **kw): @@ -232,10 +154,3 @@ def raw_print_err(*args, **kw): print(*args, sep=kw.get('sep', ' '), end=kw.get('end', '\n'), file=sys.__stderr__) sys.__stderr__.flush() - -@undoc -def unicode_std_stream(stream='stdout'): - """DEPRECATED, moved to nbconvert.utils.io""" - warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io since IPython 4.0", DeprecationWarning, stacklevel=2) - from nbconvert.utils.io import unicode_std_stream - return unicode_std_stream(stream) diff --git a/IPython/utils/tests/test_io.py b/IPython/utils/tests/test_io.py index fa3abab..3b4c03e 100644 --- a/IPython/utils/tests/test_io.py +++ b/IPython/utils/tests/test_io.py @@ -11,7 +11,7 @@ from io import StringIO from subprocess import Popen, PIPE import unittest -from IPython.utils.io import IOStream, Tee, capture_output +from IPython.utils.io import Tee, capture_output def test_tee_simple(): @@ -48,34 +48,8 @@ class TeeTestCase(unittest.TestCase): for chan in ['stdout', 'stderr']: self.tchan(chan) -def test_io_init(): - """Test that io.stdin/out/err exist at startup""" - for name in ('stdin', 'stdout', 'stderr'): - cmd = "from IPython.utils import io;print(io.%s.__class__)"%name - with Popen([sys.executable, '-c', cmd], stdout=PIPE) as p: - p.wait() - classname = p.stdout.read().strip().decode('ascii') - # __class__ is a reference to the class object in Python 3, so we can't - # just test for string equality. - assert 'IPython.utils.io.IOStream' in classname, classname - class TestIOStream(unittest.TestCase): - def test_IOStream_init(self): - """IOStream initializes from a file-like object missing attributes. """ - # Cause a failure from getattr and dir(). (Issue #6386) - class BadStringIO(StringIO): - def __dir__(self): - attrs = super().__dir__() - attrs.append('name') - return attrs - with self.assertWarns(DeprecationWarning): - iostream = IOStream(BadStringIO()) - iostream.write('hi, bad iostream\n') - - assert not hasattr(iostream, 'name') - iostream.close() - def test_capture_output(self): """capture_output() context works"""