Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77b36a9

Browse files
committed
Remove redundant Python 2 code
1 parent 3de8810 commit 77b36a9

28 files changed

Lines changed: 136 additions & 247 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ __pycache__
2121
.DS_Store
2222
\#*#
2323
.#*
24+
.cache
2425
.coverage
2526
*.swp

IPython/core/magics/script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ def shebang(self, line, cell):
218218
print("Error while terminating subprocess (pid=%i): %s" \
219219
% (p.pid, e))
220220
return
221-
out = py3compat.bytes_to_str(out)
222-
err = py3compat.bytes_to_str(err)
221+
out = py3compat.decode(out)
222+
err = py3compat.decode(err)
223223
if args.out:
224224
self.shell.user_ns[args.out] = out
225225
else:

IPython/core/tests/test_application.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from IPython.core.application import BaseIPythonApplication
1212
from IPython.testing import decorators as dec
13-
from IPython.utils import py3compat
1413
from IPython.utils.tempdir import TemporaryDirectory
1514

1615

IPython/core/tests/test_compilerop.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
# Our own imports
2424
from IPython.core import compilerop
25-
from IPython.utils import py3compat
2625

2726
#-----------------------------------------------------------------------------
2827
# Test functions

IPython/core/tests/test_completerlib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import nose.tools as nt
1818

1919
from IPython.core.completerlib import magic_run_completer, module_completion
20-
from IPython.utils import py3compat
2120
from IPython.utils.tempdir import TemporaryDirectory
2221
from IPython.testing.decorators import onlyif_unicode_paths
2322

IPython/core/tests/test_history.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from traitlets.config.loader import Config
2020
from IPython.utils.tempdir import TemporaryDirectory
2121
from IPython.core.history import HistoryManager, extract_hist_ranges
22-
from IPython.utils import py3compat
2322

2423
def setUp():
2524
nt.assert_equal(sys.getdefaultencoding(), "utf-8")

IPython/core/tests/test_interactiveshell.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import tempfile
1818
import unittest
1919
from unittest import mock
20-
from io import StringIO
2120

2221
from os.path import join
2322

@@ -30,7 +29,6 @@
3029
)
3130
from IPython.testing import tools as tt
3231
from IPython.utils.process import find_cmd
33-
from IPython.utils import py3compat
3432

3533
#-----------------------------------------------------------------------------
3634
# Globals

IPython/core/tests/test_oinspect.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
register_line_cell_magic)
2020
from decorator import decorator
2121
from IPython import get_ipython
22-
from IPython.testing.decorators import skipif
2322
from IPython.testing.tools import AssertPrints, AssertNotPrints
2423
from IPython.utils.path import compress_user
25-
from IPython.utils import py3compat
2624

2725

2826
#-----------------------------------------------------------------------------
@@ -40,14 +38,14 @@
4038
# defined, if any code is inserted above, the following line will need to be
4139
# updated. Do NOT insert any whitespace between the next line and the function
4240
# definition below.
43-
THIS_LINE_NUMBER = 43 # Put here the actual number of this line
41+
THIS_LINE_NUMBER = 41 # Put here the actual number of this line
4442

4543
from unittest import TestCase
4644

4745
class Test(TestCase):
4846

4947
def test_find_source_lines(self):
50-
self.assertEqual(oinspect.find_source_lines(Test.test_find_source_lines),
48+
self.assertEqual(oinspect.find_source_lines(Test.test_find_source_lines),
5149
THIS_LINE_NUMBER+6)
5250

5351

IPython/core/tests/test_splitinput.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from IPython.core.splitinput import split_user_input, LineInfo
55
from IPython.testing import tools as tt
6-
from IPython.utils import py3compat
76

87
tests = [
98
('x=1', ('', '', 'x', '=1')),

IPython/core/ultratb.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,35 +1136,32 @@ def structured_traceback(self, etype, evalue, etb, tb_offset=None,
11361136
colorsnormal = colors.Normal # used a lot
11371137
head = '%s%s%s' % (colors.topline, '-' * min(75, get_terminal_size()[0]), colorsnormal)
11381138
structured_traceback_parts = [head]
1139-
if py3compat.PY3:
1140-
chained_exceptions_tb_offset = 0
1141-
lines_of_context = 3
1142-
formatted_exceptions = formatted_exception
1139+
chained_exceptions_tb_offset = 0
1140+
lines_of_context = 3
1141+
formatted_exceptions = formatted_exception
1142+
exception = self.get_parts_of_chained_exception(evalue)
1143+
if exception:
1144+
formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
1145+
etype, evalue, etb = exception
1146+
else:
1147+
evalue = None
1148+
chained_exc_ids = set()
1149+
while evalue:
1150+
formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
1151+
chained_exceptions_tb_offset)
11431152
exception = self.get_parts_of_chained_exception(evalue)
1144-
if exception:
1153+
1154+
if exception and not id(exception[1]) in chained_exc_ids:
1155+
chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop
11451156
formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
11461157
etype, evalue, etb = exception
11471158
else:
11481159
evalue = None
1149-
chained_exc_ids = set()
1150-
while evalue:
1151-
formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
1152-
chained_exceptions_tb_offset)
1153-
exception = self.get_parts_of_chained_exception(evalue)
1154-
1155-
if exception and not id(exception[1]) in chained_exc_ids:
1156-
chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop
1157-
formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
1158-
etype, evalue, etb = exception
1159-
else:
1160-
evalue = None
11611160

1162-
# we want to see exceptions in a reversed order:
1163-
# the first exception should be on top
1164-
for formatted_exception in reversed(formatted_exceptions):
1165-
structured_traceback_parts += formatted_exception
1166-
else:
1167-
structured_traceback_parts += formatted_exception[0]
1161+
# we want to see exceptions in a reversed order:
1162+
# the first exception should be on top
1163+
for formatted_exception in reversed(formatted_exceptions):
1164+
structured_traceback_parts += formatted_exception
11681165

11691166
return structured_traceback_parts
11701167

0 commit comments

Comments
 (0)