diff --git a/IPython/core/display.py b/IPython/core/display.py index 8ac4ee6..c94b0b1 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -18,7 +18,7 @@ import struct import sys import warnings -from IPython.utils.py3compat import cast_bytes_py2, cast_unicode, unicode_type +from IPython.utils.py3compat import cast_bytes_py2, cast_unicode from IPython.testing.skipdoctest import skip_doctest __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown', @@ -492,7 +492,7 @@ class DisplayObject(object): self.data = data self.url = url - self.filename = None if filename is None else unicode_type(filename) + self.filename = filename self.reload() self._check_data() @@ -876,7 +876,7 @@ class Image(DisplayObject): # jpg->jpeg format = self._FMT_JPEG - self.format = unicode_type(format).lower() + self.format = format.lower() self.embed = embed if embed is not None else (url is None) if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS: @@ -953,7 +953,7 @@ class Image(DisplayObject): return self._data_and_metadata() def _find_ext(self, s): - return unicode_type(s.split('.')[-1].lower()) + return s.split('.')[-1].lower() class Video(DisplayObject): @@ -1037,7 +1037,7 @@ class Video(DisplayObject): video = f.read() else: video = self.data - if isinstance(video, unicode_type): + if isinstance(video, str): # unicode input is already b64-encoded b64_video = video else: diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index 31de644..28f61e2 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -29,7 +29,7 @@ from traitlets import ( default, observe, ) from IPython.utils.py3compat import ( - with_metaclass, unicode_type, + with_metaclass ) @@ -737,7 +737,7 @@ class PNGFormatter(BaseFormatter): print_method = ObjectName('_repr_png_') - _return_type = (bytes, unicode_type) + _return_type = (bytes, str) class JPEGFormatter(BaseFormatter): @@ -755,7 +755,7 @@ class JPEGFormatter(BaseFormatter): print_method = ObjectName('_repr_jpeg_') - _return_type = (bytes, unicode_type) + _return_type = (bytes, str) class LatexFormatter(BaseFormatter): @@ -846,7 +846,7 @@ class PDFFormatter(BaseFormatter): print_method = ObjectName('_repr_pdf_') - _return_type = (bytes, unicode_type) + _return_type = (bytes, str) class IPythonDisplayFormatter(BaseFormatter): """A Formatter for objects that know how to display themselves. diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 45050b0..c892c22 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -67,7 +67,7 @@ from IPython.utils.ipstruct import Struct from IPython.paths import get_ipython_dir from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists from IPython.utils.process import system, getoutput -from IPython.utils.py3compat import builtin_mod, unicode_type, with_metaclass +from IPython.utils.py3compat import builtin_mod, with_metaclass from IPython.utils.strdispatch import StrDispatch from IPython.utils.syspathcontext import prepended_to_syspath from IPython.utils.text import format_screen, LSString, SList, DollarFormatter @@ -2340,7 +2340,7 @@ class InteractiveShell(SingletonConfigurable): exc_info = { u'status' : 'error', u'traceback' : stb, - u'ename' : unicode_type(etype.__name__), + u'ename' : etype.__name__, u'evalue' : py3compat.safe_unicode(evalue), } diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index c2427c9..475ddf8 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -12,7 +12,6 @@ from IPython.core.magic import Magics, magics_class, line_magic, magic_escapes from IPython.utils.text import format_screen, dedent, indent from IPython.testing.skipdoctest import skip_doctest from IPython.utils.ipstruct import Struct -from IPython.utils.py3compat import unicode_type from warnings import warn from logging import error @@ -550,7 +549,7 @@ Currently the magic system has the following functions:""", help=argparse.SUPPRESS ) @magic_arguments.argument( - 'filename', type=unicode_type, + 'filename', type=str, help='Notebook name or filename' ) @line_magic diff --git a/IPython/core/magics/namespace.py b/IPython/core/magics/namespace.py index 68442f9..343db92 100644 --- a/IPython/core/magics/namespace.py +++ b/IPython/core/magics/namespace.py @@ -25,7 +25,6 @@ from IPython.testing.skipdoctest import skip_doctest from IPython.utils.encoding import DEFAULT_ENCODING from IPython.utils.openpy import read_py_file from IPython.utils.path import get_py_filename -from IPython.utils.py3compat import unicode_type #----------------------------------------------------------------------------- # Magic implementation classes @@ -460,8 +459,8 @@ class NamespaceMagics(Magics): try: vstr = str(var) except UnicodeEncodeError: - vstr = unicode_type(var).encode(DEFAULT_ENCODING, - 'backslashreplace') + vstr = var.encode(DEFAULT_ENCODING, + 'backslashreplace') except: vstr = "" % id(var) vstr = vstr.replace('\n', '\\n') diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index 0d85a01..a301ee4 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -35,7 +35,6 @@ from IPython.testing.skipdoctest import skip_doctest from IPython.utils.openpy import source_to_unicode from IPython.utils.process import abbrev_cwd from IPython.utils import py3compat -from IPython.utils.py3compat import unicode_type from IPython.utils.terminal import set_term_title #----------------------------------------------------------------------------- @@ -764,7 +763,7 @@ class OSMagics(Magics): 'The file will be created if it does not exist.' ) @magic_arguments.argument( - 'filename', type=unicode_type, + 'filename', type=str, help='file to write' ) @cell_magic diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 7802bc5..93ec7f9 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -20,7 +20,7 @@ class LazyEvaluate(object): return str(self()) def __unicode__(self): - return py3compat.unicode_type(self()) + return self.__str__() def __format__(self, format_spec): return format(self(), format_spec) diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index 4b81de6..142da78 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -18,7 +18,6 @@ from IPython.core import completer from IPython.external.decorators import knownfailureif from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory from IPython.utils.generics import complete_object -from IPython.utils.py3compat import unicode_type from IPython.testing import decorators as dec #----------------------------------------------------------------------------- @@ -102,7 +101,7 @@ def test_line_split(): check_line_split(sp, t) # Ensure splitting works OK with unicode by re-running the tests with # all inputs turned into unicode - check_line_split(sp, [ map(unicode_type, p) for p in t] ) + check_line_split(sp, [ map(str, p) for p in t] ) def test_custom_completion_error(): @@ -123,7 +122,7 @@ def test_unicode_completions(): # Some strings that trigger different types of completion. Check them both # in str and unicode forms s = ['ru', '%ru', 'cd /', 'floa', 'float(x)/'] - for t in s + list(map(unicode_type, s)): + for t in s + list(map(str, s)): # We don't need to check exact completion values (they may change # depending on the state of the namespace, but at least no exceptions # should be thrown and the return value should be a pair of text, list diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index a350316..65190aa 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -32,7 +32,7 @@ from IPython.testing.decorators import ( from IPython.testing import tools as tt from IPython.utils.process import find_cmd from IPython.utils import py3compat -from IPython.utils.py3compat import unicode_type, PY3 +from IPython.utils.py3compat import PY3 if PY3: from io import StringIO @@ -473,7 +473,7 @@ class InteractiveShellTestCase(unittest.TestCase): def test_inspect_text(self): ip.run_cell('a = 5') text = ip.object_inspect_text('a') - self.assertIsInstance(text, unicode_type) + self.assertIsInstance(text, str) class TestSafeExecfileNonAsciiPath(unittest.TestCase): diff --git a/IPython/core/tests/test_prompts.py b/IPython/core/tests/test_prompts.py index 6595dab..4082b14 100644 --- a/IPython/core/tests/test_prompts.py +++ b/IPython/core/tests/test_prompts.py @@ -5,7 +5,6 @@ import unittest from IPython.core.prompts import LazyEvaluate from IPython.testing.globalipapp import get_ipython -from IPython.utils.py3compat import unicode_type ip = get_ipython() @@ -14,8 +13,7 @@ class PromptTests(unittest.TestCase): def test_lazy_eval_unicode(self): u = u'ünicødé' lz = LazyEvaluate(lambda : u) - # str(lz) would fail - self.assertEqual(unicode_type(lz), u) + self.assertEqual(str(lz), u) self.assertEqual(format(lz), u) def test_lazy_eval_nonascii_bytes(self): @@ -31,7 +29,6 @@ class PromptTests(unittest.TestCase): lz = LazyEvaluate(lambda : f) self.assertEqual(str(lz), str(f)) - self.assertEqual(unicode_type(lz), unicode_type(f)) self.assertEqual(format(lz), str(f)) self.assertEqual(format(lz, '.1'), '0.5') diff --git a/IPython/lib/tests/test_clipboard.py b/IPython/lib/tests/test_clipboard.py index c0d6ed9..f1050bf 100644 --- a/IPython/lib/tests/test_clipboard.py +++ b/IPython/lib/tests/test_clipboard.py @@ -3,7 +3,6 @@ import nose.tools as nt from IPython.core.error import TryNext from IPython.lib.clipboard import ClipboardEmpty from IPython.testing.decorators import skip_if_no_x11 -from IPython.utils.py3compat import unicode_type @skip_if_no_x11 def test_clipboard_get(): @@ -19,4 +18,4 @@ def test_clipboard_get(): # No clipboard access API available pass else: - nt.assert_is_instance(a, unicode_type) + nt.assert_is_instance(a, str) diff --git a/IPython/utils/openpy.py b/IPython/utils/openpy.py index 1ec22a4..ad7e267 100644 --- a/IPython/utils/openpy.py +++ b/IPython/utils/openpy.py @@ -10,7 +10,6 @@ from io import TextIOWrapper, BytesIO import os.path import re -from .py3compat import unicode_type cookie_re = re.compile(r"coding[:=]\s*([-\w.]+)", re.UNICODE) cookie_comment_re = re.compile(r"^\s*#.*coding[:=]\s*([-\w.]+)", re.UNICODE) @@ -129,7 +128,7 @@ def source_to_unicode(txt, errors='replace', skip_encoding_cookie=True): txt can be either a bytes buffer or a string containing the source code. """ - if isinstance(txt, unicode_type): + if isinstance(txt, str): return txt if isinstance(txt, bytes): buffer = BytesIO(txt) diff --git a/IPython/utils/ulinecache.py b/IPython/utils/ulinecache.py index f53b0dd..e12819d 100644 --- a/IPython/utils/ulinecache.py +++ b/IPython/utils/ulinecache.py @@ -25,8 +25,7 @@ else: filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding()) lines = linecache.getlines(filename, module_globals=module_globals) - # The bits we cache ourselves can be unicode. - if (not lines) or isinstance(lines[0], py3compat.unicode_type): + if (not lines) or isinstance(lines[0], str): return lines readline = openpy._list_readline(lines)