diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 4a06c5a..58e20c4 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -139,7 +139,6 @@ from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol from IPython.utils import generics from IPython.utils.dir2 import dir2, get_real_method from IPython.utils.process import arg_split -from IPython.utils.py3compat import cast_unicode_py2 from traitlets import Bool, Enum, observe, Int try: @@ -665,7 +664,7 @@ class Completer(Configurable): for word in shortened.keys(): if word[:n] == text and word != "__builtins__": match_append(shortened[word]) - return [cast_unicode_py2(m) for m in matches] + return matches def attr_matches(self, text): """Compute matches when text contains a dot. @@ -729,7 +728,7 @@ def get__all__entries(obj): except: return [] - return [cast_unicode_py2(w) for w in words if isinstance(w, str)] + return [w for w in words if isinstance(w, str)] def match_dict_keys(keys: List[str], prefix: str, delims: str): @@ -1125,7 +1124,7 @@ class IPCompleter(Completer): text = os.path.expanduser(text) if text == "": - return [text_prefix + cast_unicode_py2(protect_filename(f)) for f in self.glob("*")] + return [text_prefix + protect_filename(f) for f in self.glob("*")] # Compute the matches from the filesystem if sys.platform == 'win32': @@ -1152,7 +1151,7 @@ class IPCompleter(Completer): protect_filename(f) for f in m0] # Mark directories in input list by appending '/' to their names. - return [cast_unicode_py2(x+'/') if os.path.isdir(x) else x for x in matches] + return [x+'/' if os.path.isdir(x) else x for x in matches] def magic_matches(self, text): """Match magics""" @@ -1180,7 +1179,7 @@ class IPCompleter(Completer): if not text.startswith(pre2): comp += [ pre+m for m in line_magics if matches(m)] - return [cast_unicode_py2(c) for c in comp] + return comp def magic_config_matches(self, text): """ Match class names and attributes for %config magic """ @@ -1637,12 +1636,12 @@ class IPCompleter(Completer): res = c(event) if res: # first, try case sensitive match - withcase = [cast_unicode_py2(r) for r in res if r.startswith(text)] + withcase = [r for r in res if r.startswith(text)] if withcase: return withcase # if none, then case insensitive ones are ok too text_low = text.lower() - return [cast_unicode_py2(r) for r in res if r.lower().startswith(text_low)] + return [r for r in res if r.lower().startswith(text_low)] except TryNext: pass diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index 3680a72..a236522 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -13,7 +13,6 @@ import io as _io import tokenize from traitlets.config.configurable import Configurable -from IPython.utils.py3compat import cast_unicode_py2 from traitlets import Instance, Float from warnings import warn @@ -87,7 +86,7 @@ class DisplayHook(Configurable): # do not print output if input ends in ';' try: - cell = cast_unicode_py2(self.shell.history_manager.input_hist_parsed[-1]) + cell = self.shell.history_manager.input_hist_parsed[-1] except IndexError: # some uses of ipshellembed may fail here return False diff --git a/IPython/core/magics/history.py b/IPython/core/magics/history.py index af3d0b1..3a3c5c8 100644 --- a/IPython/core/magics/history.py +++ b/IPython/core/magics/history.py @@ -24,7 +24,6 @@ from IPython.core.magic_arguments import (argument, magic_arguments, parse_argstring) from IPython.testing.skipdoctest import skip_doctest from IPython.utils import io -from IPython.utils.py3compat import cast_unicode_py2 #----------------------------------------------------------------------------- # Magics class implementation @@ -214,7 +213,7 @@ class HistoryMagics(Magics): inline = "\n... ".join(inline.splitlines()) + "\n..." print(inline, file=outfile) if get_output and output: - print(cast_unicode_py2(output), file=outfile) + print(output, file=outfile) if close_at_end: outfile.close() diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 0004e7d..c03b8ff 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -328,7 +328,6 @@ def fix_frame_records_filenames(records): # Look inside the frame's globals dictionary for __file__, # which should be better. However, keep Cython filenames since # we prefer the source filenames over the compiled .so file. - filename = py3compat.cast_unicode_py2(filename, "utf-8") if not filename.endswith(('.pyx', '.pxd', '.pxi')): better_fn = frame.f_globals.get('__file__', None) if isinstance(better_fn, str): @@ -382,8 +381,6 @@ def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, _line_forma i = lnum - index for line in lines: - line = py3compat.cast_unicode(line) - new_line, err = _line_format(line, 'str') if not err: line = new_line @@ -652,9 +649,9 @@ class ListTB(TBTools): list = [] for filename, lineno, name, line in extracted_list[:-1]: item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \ - (Colors.filename, py3compat.cast_unicode_py2(filename, "utf-8"), Colors.Normal, + (Colors.filename, filename, Colors.Normal, Colors.lineno, lineno, Colors.Normal, - Colors.name, py3compat.cast_unicode_py2(name, "utf-8"), Colors.Normal) + Colors.name, name, Colors.Normal) if line: item += ' %s\n' % line.strip() list.append(item) @@ -662,9 +659,9 @@ class ListTB(TBTools): filename, lineno, name, line = extracted_list[-1] item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \ (Colors.normalEm, - Colors.filenameEm, py3compat.cast_unicode_py2(filename, "utf-8"), Colors.normalEm, + Colors.filenameEm, filename, Colors.normalEm, Colors.linenoEm, lineno, Colors.normalEm, - Colors.nameEm, py3compat.cast_unicode_py2(name, "utf-8"), Colors.normalEm, + Colors.nameEm, name, Colors.normalEm, Colors.Normal) if line: item += '%s %s%s\n' % (Colors.line, line.strip(), @@ -688,7 +685,7 @@ class ListTB(TBTools): have_filedata = False Colors = self.Colors list = [] - stype = py3compat.cast_unicode(Colors.excName + etype.__name__ + Colors.Normal) + stype = Colors.excName + etype.__name__ + Colors.Normal if value is None: # Not sure if this can still happen in Python 2.6 and above list.append(stype + '\n') @@ -704,10 +701,10 @@ class ListTB(TBTools): textline = '' list.append('%s File %s"%s"%s, line %s%s%s\n' % \ (Colors.normalEm, - Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm, + Colors.filenameEm, value.filename, Colors.normalEm, Colors.linenoEm, lineno, Colors.Normal )) if textline == '': - textline = py3compat.cast_unicode(value.text, "utf-8") + textline = value.text if textline is not None: i = 0 @@ -772,7 +769,7 @@ class ListTB(TBTools): def _some_str(self, value): # Lifted from traceback.py try: - return py3compat.cast_unicode(str(value)) + return str(value) except: return u'' % type(value).__name__ @@ -869,7 +866,6 @@ class VerboseTB(TBTools): # strange entries... pass - file = py3compat.cast_unicode(file, util_path.fs_encoding) link = tpl_link % util_path.compress_user(file) args, varargs, varkw, locals = inspect.getargvalues(frame) @@ -1047,8 +1043,7 @@ class VerboseTB(TBTools): etype, evalue = str, sys.exc_info()[:2] etype_str, evalue_str = map(str, (etype, evalue)) # ... and format it - return ['%s%s%s: %s' % (colors.excName, etype_str, - colorsnormal, py3compat.cast_unicode(evalue_str))] + return ['%s%s%s: %s' % (colors.excName, etype_str, colorsnormal, evalue_str)] def format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset): """Formats the header, traceback and exception message for a single exception. diff --git a/IPython/lib/latextools.py b/IPython/lib/latextools.py index 7737c0f..4de9ecc 100644 --- a/IPython/lib/latextools.py +++ b/IPython/lib/latextools.py @@ -15,7 +15,7 @@ from IPython.utils.process import find_cmd, FindCmdError from traitlets.config import get_config from traitlets.config.configurable import SingletonConfigurable from traitlets import List, Bool, Unicode -from IPython.utils.py3compat import cast_unicode, cast_unicode_py2 as u +from IPython.utils.py3compat import cast_unicode class LaTeXTool(SingletonConfigurable): @@ -161,20 +161,20 @@ def genelatex(body, wrap): """Generate LaTeX document for dvipng backend.""" lt = LaTeXTool.instance() breqn = wrap and lt.use_breqn and kpsewhich("breqn.sty") - yield u(r'\documentclass{article}') + yield r'\documentclass{article}' packages = lt.packages if breqn: packages = packages + ['breqn'] for pack in packages: - yield u(r'\usepackage{{{0}}}'.format(pack)) - yield u(r'\pagestyle{empty}') + yield r'\usepackage{{{0}}}'.format(pack) + yield r'\pagestyle{empty}' if lt.preamble: yield lt.preamble - yield u(r'\begin{document}') + yield r'\begin{document}' if breqn: - yield u(r'\begin{dmath*}') + yield r'\begin{dmath*}' yield body - yield u(r'\end{dmath*}') + yield r'\end{dmath*}' elif wrap: yield u'$${0}$$'.format(body) else: diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 315d1f1..14b9970 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -7,7 +7,7 @@ from warnings import warn from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.utils import io -from IPython.utils.py3compat import cast_unicode_py2, input +from IPython.utils.py3compat import input from IPython.utils.terminal import toggle_set_term_title, set_term_title from IPython.utils.process import abbrev_cwd from traitlets import ( @@ -227,7 +227,7 @@ class TerminalInteractiveShell(InteractiveShell): # Fall back to plain non-interactive output for tests. # This is very limited, and only accepts a single line. def prompt(): - return cast_unicode_py2(input('In [%d]: ' % self.execution_count)) + return input('In [%d]: ' % self.execution_count) self.prompt_for_code = prompt return @@ -432,7 +432,7 @@ class TerminalInteractiveShell(InteractiveShell): # We can't set the buffer here, because it will be reset just after # this. Adding a callable to pre_run_callables does what we need # after the buffer is reset. - s = cast_unicode_py2(self.rl_next_input) + s = self.rl_next_input def set_doc(): self.pt_cli.application.buffer.document = Document(s) if hasattr(self.pt_cli, 'pre_run_callables'): diff --git a/IPython/utils/tokenutil.py b/IPython/utils/tokenutil.py index 02155d1..9bc847a 100644 --- a/IPython/utils/tokenutil.py +++ b/IPython/utils/tokenutil.py @@ -3,13 +3,12 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. - from collections import namedtuple from io import StringIO from keyword import iskeyword from . import tokenize2 -from .py3compat import cast_unicode_py2 + Token = namedtuple('Token', ['token', 'text', 'start', 'end', 'line']) @@ -68,7 +67,6 @@ def token_at_cursor(cell, cursor_pos=0): cursor_pos : int The location of the cursor in the block where the token should be found """ - cell = cast_unicode_py2(cell) names = [] tokens = [] call_names = []