From 3a5799a9d2d0d1f54a51ab07b89997518857b999 2017-01-09 13:22:06 From: Thomas Kluyver Date: 2017-01-09 13:22:06 Subject: [PATCH] Merge pull request #10134 from srinivasreddy/rm_PY3 Remove PY3 variable --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 3e2ab79..2712abb 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -35,7 +35,7 @@ from IPython.utils import generics from IPython.utils.decorators import undoc from IPython.utils.dir2 import dir2, get_real_method from IPython.utils.process import arg_split -from IPython.utils.py3compat import builtin_mod, PY3, cast_unicode_py2 +from IPython.utils.py3compat import builtin_mod, cast_unicode_py2 from traitlets import Bool, Enum, observe from functools import wraps @@ -1172,18 +1172,16 @@ class IPCompleter(Completer): if self.use_main_ns: self.namespace = __main__.__dict__ - if PY3: - - base_text = text if not line_buffer else line_buffer[:cursor_pos] - latex_text, latex_matches = self.latex_matches(base_text) - if latex_matches: - return latex_text, latex_matches - name_text = '' - name_matches = [] - for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches): - name_text, name_matches = meth(base_text) - if name_text: - return name_text, name_matches + base_text = text if not line_buffer else line_buffer[:cursor_pos] + latex_text, latex_matches = self.latex_matches(base_text) + if latex_matches: + return latex_text, latex_matches + name_text = '' + name_matches = [] + for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches): + name_text, name_matches = meth(base_text) + if name_text: + return name_text, name_matches # if text is either None or an empty string, rely on the line buffer if not text: diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py index d3a8ba7..9036add 100644 --- a/IPython/core/inputtransformer.py +++ b/IPython/core/inputtransformer.py @@ -6,17 +6,12 @@ This includes the machinery to recognise and transform ``%magic`` commands, import abc import functools import re +from io import StringIO from IPython.core.splitinput import LineInfo from IPython.utils import tokenize2 -from IPython.utils.py3compat import PY3 from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError -if PY3: - from io import StringIO -else: - from StringIO import StringIO - #----------------------------------------------------------------------------- # Globals #----------------------------------------------------------------------------- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 7279462..6334e7a 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -36,7 +36,7 @@ from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic, line_cell_magic, on_off, needs_local_scope) from IPython.testing.skipdoctest import skip_doctest from IPython.utils import py3compat -from IPython.utils.py3compat import builtin_mod, PY3 +from IPython.utils.py3compat import builtin_mod from IPython.utils.contexts import preserve_keys from IPython.utils.capture import capture_output from IPython.utils.ipstruct import Struct @@ -45,11 +45,8 @@ from IPython.utils.path import get_py_filename, shellglob from IPython.utils.timing import clock, clock2 from warnings import warn from logging import error +from io import StringIO -if PY3: - from io import StringIO -else: - from StringIO import StringIO #----------------------------------------------------------------------------- # Magic implementation classes @@ -652,9 +649,6 @@ python-profiler package from non-free.""") args = shellglob(map(os.path.expanduser, arg_lst[1:])) sys.argv = [filename] + args # put in the proper filename - # protect sys.argv from potential unicode strings on Python 2: - if not py3compat.PY3: - sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ] if 'i' in opts: # Run in user's interactive namespace diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 22e7543..a4358dd 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -303,9 +303,6 @@ class InteractiveShellApp(Configurable): # were run from a system shell. save_argv = sys.argv sys.argv = [full_filename] + self.extra_args[1:] - # protect sys.argv from potential unicode strings on Python 2: - if not py3compat.PY3: - sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ] try: if os.path.isfile(full_filename): self.log.info("Running file in user namespace: %s" % diff --git a/IPython/core/tests/test_splitinput.py b/IPython/core/tests/test_splitinput.py index c789e10..170d923 100644 --- a/IPython/core/tests/test_splitinput.py +++ b/IPython/core/tests/test_splitinput.py @@ -28,10 +28,7 @@ tests = [ ('??%%hist4', ('', '??', '%%hist4', '')), ('?x*', ('', '?', 'x*', '')), ] -if py3compat.PY3: - tests.append((u"Pérez Fernando", (u'', u'', u'Pérez', u'Fernando'))) -else: - tests.append((u"Pérez Fernando", (u'', u'', u'P', u'érez Fernando'))) +tests.append((u"Pérez Fernando", (u'', u'', u'Pérez', u'Fernando'))) def test_split_user_input(): return tt.check_pairs(split_user_input, tests) diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 07b88dd..813ea7b 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -298,7 +298,10 @@ def getargs(co): # Monkeypatch inspect to apply our bugfix. def with_patch_inspect(f): - """decorator for monkeypatching inspect.findsource""" + """ + Deprecated since IPython 6.0 + decorator for monkeypatching inspect.findsource + """ def wrapped(*args, **kwargs): save_findsource = inspect.findsource @@ -314,16 +317,6 @@ def with_patch_inspect(f): return wrapped -if py3compat.PY3: - fixed_getargvalues = inspect.getargvalues -else: - # Fixes for https://github.com/ipython/ipython/issues/8293 - # and https://github.com/ipython/ipython/issues/8205. - # The relevant bug is caused by failure to correctly handle anonymous tuple - # unpacking, which only exists in Python 2. - fixed_getargvalues = with_patch_inspect(inspect.getargvalues) - - def fix_frame_records_filenames(records): """Try to fix the filenames in each record from inspect.getinnerframes(). @@ -878,7 +871,7 @@ class VerboseTB(TBTools): file = py3compat.cast_unicode(file, util_path.fs_encoding) link = tpl_link % file - args, varargs, varkw, locals = fixed_getargvalues(frame) + args, varargs, varkw, locals = inspect.getargvalues(frame) if func == '?': call = '' diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index 84515e1..d144005 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -10,8 +10,6 @@ not to be used outside IPython. import unicodedata from wcwidth import wcwidth -from IPython.utils.py3compat import PY3 - from IPython.core.completer import IPCompleter from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.layout.lexers import Lexer @@ -78,7 +76,7 @@ class IPythonPTLexer(Lexer): """ def __init__(self): l = pygments_lexers - self.python_lexer = PygmentsLexer(l.Python3Lexer if PY3 else l.PythonLexer) + self.python_lexer = PygmentsLexer(l.Python3Lexer) self.shell_lexer = PygmentsLexer(l.BashLexer) self.magic_lexers = { diff --git a/IPython/utils/PyColorize.py b/IPython/utils/PyColorize.py index d4469f0..4693bbd 100644 --- a/IPython/utils/PyColorize.py +++ b/IPython/utils/PyColorize.py @@ -44,14 +44,8 @@ import tokenize generate_tokens = tokenize.generate_tokens from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable -from IPython.utils.py3compat import PY3 - from .colorable import Colorable - -if PY3: - from io import StringIO -else: - from StringIO import StringIO +from io import StringIO ############################################################################# ### Python Source Parser (does Highlighting) diff --git a/IPython/utils/capture.py b/IPython/utils/capture.py index 64044ce..a39813e 100644 --- a/IPython/utils/capture.py +++ b/IPython/utils/capture.py @@ -6,13 +6,7 @@ import sys - -from IPython.utils.py3compat import PY3 - -if PY3: - from io import StringIO -else: - from StringIO import StringIO +from io import StringIO #----------------------------------------------------------------------------- # Classes and functions diff --git a/IPython/utils/io.py b/IPython/utils/io.py index dcbef22..173d602 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -17,7 +17,7 @@ from warnings import warn from IPython.utils.decorators import undoc from .capture import CapturedIO, capture_output -from .py3compat import input, PY3 +from .py3compat import input @undoc class IOStream: diff --git a/IPython/utils/tests/test_io.py b/IPython/utils/tests/test_io.py index 5f9e87e..b23a4a3 100644 --- a/IPython/utils/tests/test_io.py +++ b/IPython/utils/tests/test_io.py @@ -9,6 +9,7 @@ import io as stdlib_io import os.path import stat import sys +from io import StringIO from subprocess import Popen, PIPE import unittest @@ -17,14 +18,9 @@ import nose.tools as nt from IPython.testing.decorators import skipif, skip_win32 from IPython.utils.io import Tee, capture_output -from IPython.utils.py3compat import doctest_refactor_print, PY3 +from IPython.utils.py3compat import doctest_refactor_print from IPython.utils.tempdir import TemporaryDirectory -if PY3: - from io import StringIO -else: - from StringIO import StringIO - def test_tee_simple(): "Very simple check with stdout only" diff --git a/IPython/utils/ulinecache.py b/IPython/utils/ulinecache.py index e12819d..943de05 100644 --- a/IPython/utils/ulinecache.py +++ b/IPython/utils/ulinecache.py @@ -1,44 +1,25 @@ -"""Wrapper around linecache which decodes files to unicode according to PEP 263. +""" +This module has been deprecated since IPython 6.0. -This is only needed for Python 2 - linecache in Python 3 does the same thing -itself. +Wrapper around linecache which decodes files to unicode according to PEP 263. """ import functools import linecache import sys +from warnings import warn from IPython.utils import py3compat from IPython.utils import openpy -if py3compat.PY3: - getline = linecache.getline - - # getlines has to be looked up at runtime, because doctests monkeypatch it. - @functools.wraps(linecache.getlines) - def getlines(filename, module_globals=None): - return linecache.getlines(filename, module_globals=module_globals) - -else: - def getlines(filename, module_globals=None): - """Get the lines (as unicode) for a file from the cache. - Update the cache if it doesn't contain an entry for this file already.""" - filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding()) - lines = linecache.getlines(filename, module_globals=module_globals) - - if (not lines) or isinstance(lines[0], str): - return lines - - readline = openpy._list_readline(lines) - try: - encoding, _ = openpy.detect_encoding(readline) - except SyntaxError: - encoding = 'ascii' - return [l.decode(encoding, 'replace') for l in lines] +getline = linecache.getline - # This is a straight copy of linecache.getline - def getline(filename, lineno, module_globals=None): - lines = getlines(filename, module_globals) - if 1 <= lineno <= len(lines): - return lines[lineno-1] - else: - return '' +# getlines has to be looked up at runtime, because doctests monkeypatch it. +@functools.wraps(linecache.getlines) +def getlines(filename, module_globals=None): + """ + Deprecated since IPython 6.0 + """ + warn(("`IPython.utils.ulinecache.getlines` is deprecated since" + " IPython 6.0 and will be removed in future versions."), + DeprecationWarning, stacklevel=2) + return linecache.getlines(filename, module_globals=module_globals)