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

Skip to content

Commit 7851f8a

Browse files
committed
remove sys_version for Python 3
since we're now committed to using Python3, I decided to go through and clean up the code base to remove paths which depend on sys_version checks for Python3
1 parent 6b34d35 commit 7851f8a

15 files changed

Lines changed: 651 additions & 1193 deletions

IPython/core/debugger.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -604,22 +604,21 @@ def do_psource(self, arg):
604604
('Globals', self.curframe.f_globals)]
605605
self.shell.find_line_magic('psource')(arg, namespaces=namespaces)
606606

607-
if sys.version_info > (3, ):
608-
def do_where(self, arg):
609-
"""w(here)
610-
Print a stack trace, with the most recent frame at the bottom.
611-
An arrow indicates the "current frame", which determines the
612-
context of most commands. 'bt' is an alias for this command.
613-
614-
Take a number as argument as an (optional) number of context line to
615-
print"""
616-
if arg:
617-
context = int(arg)
618-
self.print_stack_trace(context)
619-
else:
620-
self.print_stack_trace()
607+
def do_where(self, arg):
608+
"""w(here)
609+
Print a stack trace, with the most recent frame at the bottom.
610+
An arrow indicates the "current frame", which determines the
611+
context of most commands. 'bt' is an alias for this command.
612+
613+
Take a number as argument as an (optional) number of context line to
614+
print"""
615+
if arg:
616+
context = int(arg)
617+
self.print_stack_trace(context)
618+
else:
619+
self.print_stack_trace()
621620

622-
do_w = do_where
621+
do_w = do_where
623622

624623

625624
def set_trace(frame=None):

IPython/core/interactiveshell.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,7 @@ def raise_error(self):
187187
raise self.error_in_exec
188188

189189
def __repr__(self):
190-
if sys.version_info > (3,):
191-
name = self.__class__.__qualname__
192-
else:
193-
name = self.__class__.__name__
190+
name = self.__class__.__qualname__
194191
return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s result=%s>' %\
195192
(name, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.result))
196193

IPython/core/tests/test_completer.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def test_latex_completions():
155155

156156

157157

158-
@dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
159158
def test_back_latex_completion():
160159
ip = get_ipython()
161160

@@ -164,7 +163,6 @@ def test_back_latex_completion():
164163
nt.assert_equal(len(matches), 1)
165164
nt.assert_equal(matches[0], '\\beta')
166165

167-
@dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
168166
def test_back_unicode_completion():
169167
ip = get_ipython()
170168

@@ -173,15 +171,13 @@ def test_back_unicode_completion():
173171
nt.assert_equal(matches[0], '\\ROMAN NUMERAL FIVE')
174172

175173

176-
@dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
177174
def test_forward_unicode_completion():
178175
ip = get_ipython()
179176

180177
name, matches = ip.complete('\\ROMAN NUMERAL FIVE')
181178
nt.assert_equal(len(matches), 1)
182179
nt.assert_equal(matches[0], 'Ⅴ')
183180

184-
@dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3')
185181
@dec.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path')
186182
def test_no_ascii_back_completion():
187183
ip = get_ipython()
@@ -588,7 +584,6 @@ def assert_completion(**kwargs):
588584

589585

590586

591-
@dec.onlyif(sys.version_info[0] >= 3, 'This test only applies in Py>=3')
592587
def test_dict_key_completion_bytes():
593588
"""Test handling of bytes in dict key completion"""
594589
ip = get_ipython()
@@ -618,7 +613,6 @@ def test_dict_key_completion_bytes():
618613
nt.assert_not_in("abd", matches)
619614

620615

621-
@dec.onlyif(sys.version_info[0] < 3, 'This test only applies in Py<3')
622616
def test_dict_key_completion_unicode_py2():
623617
"""Test handling of unicode in dict key completion"""
624618
ip = get_ipython()
@@ -679,7 +673,6 @@ def test_dict_key_completion_unicode_py2():
679673
nt.assert_in(u"d[u'a\u05d0b']", matches)
680674

681675

682-
@dec.onlyif(sys.version_info[0] >= 3, 'This test only applies in Py>=3')
683676
def test_dict_key_completion_unicode_py3():
684677
"""Test handling of unicode in dict key completion"""
685678
ip = get_ipython()

IPython/core/tests/test_interactiveshell.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -338,19 +338,6 @@ def failing_hook(*args, **kwargs):
338338
finally:
339339
trap.hook = save_hook
340340

341-
@skipif(sys.version_info[0] >= 3, "softspace removed in py3")
342-
def test_print_softspace(self):
343-
"""Verify that softspace is handled correctly when executing multiple
344-
statements.
345-
346-
In [1]: print 1; print 2
347-
1
348-
2
349-
350-
In [2]: print 1,; print 2
351-
1 2
352-
"""
353-
354341
def test_ofind_line_magic(self):
355342
from IPython.core.magic import register_line_magic
356343

@@ -466,22 +453,6 @@ def my_handler(shell, etype, value, tb, tb_offset=None):
466453
# Reset the custom exception hook
467454
ip.set_custom_exc((), None)
468455

469-
@skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
470-
def test_future_environment(self):
471-
"Can we run code with & without the shell's __future__ imports?"
472-
ip.run_cell("from __future__ import division")
473-
ip.run_cell("a = 1/2", shell_futures=True)
474-
self.assertEqual(ip.user_ns['a'], 0.5)
475-
ip.run_cell("b = 1/2", shell_futures=False)
476-
self.assertEqual(ip.user_ns['b'], 0)
477-
478-
ip.compile.reset_compiler_flags()
479-
# This shouldn't leak to the shell's compiler
480-
ip.run_cell("from __future__ import division \nc=1/2", shell_futures=False)
481-
self.assertEqual(ip.user_ns['c'], 0.5)
482-
ip.run_cell("d = 1/2", shell_futures=True)
483-
self.assertEqual(ip.user_ns['d'], 0)
484-
485456
def test_mktempfile(self):
486457
filename = ip.mktempfile()
487458
# Check that we can open the file again on Windows
@@ -509,10 +480,7 @@ def test_get_exception_only(self):
509480
raise DerivedInterrupt("foo")
510481
except KeyboardInterrupt:
511482
msg = ip.get_exception_only()
512-
if sys.version_info[0] <= 2:
513-
self.assertEqual(msg, 'DerivedInterrupt: foo\n')
514-
else:
515-
self.assertEqual(msg, 'IPython.core.tests.test_interactiveshell.DerivedInterrupt: foo\n')
483+
self.assertEqual(msg, 'IPython.core.tests.test_interactiveshell.DerivedInterrupt: foo\n')
516484

517485
def test_inspect_text(self):
518486
ip.run_cell('a = 5')

IPython/core/tests/test_magic.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,6 @@ def test_time3():
377377
"run = 0\n"
378378
"run += 1")
379379

380-
@dec.skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
381-
def test_time_futures():
382-
"Test %time with __future__ environments"
383-
ip = get_ipython()
384-
ip.autocall = 0
385-
ip.run_cell("from __future__ import division")
386-
with tt.AssertPrints('0.25'):
387-
ip.run_line_magic('time', 'print(1/4)')
388-
ip.compile.reset_compiler_flags()
389-
with tt.AssertNotPrints('0.25'):
390-
ip.run_line_magic('time', 'print(1/4)')
391-
392380
def test_doctest_mode():
393381
"Toggle doctest_mode twice, it should be a no-op and run without error"
394382
_ip.magic('doctest_mode')
@@ -573,17 +561,6 @@ def test_timeit_return_quiet():
573561
res = _ip.run_line_magic('timeit', '-n1 -r1 -q -o 1')
574562
assert (res is not None)
575563

576-
@dec.skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
577-
def test_timeit_futures():
578-
"Test %timeit with __future__ environments"
579-
ip = get_ipython()
580-
ip.run_cell("from __future__ import division")
581-
with tt.AssertPrints('0.25'):
582-
ip.run_line_magic('timeit', '-n1 -r1 print(1/4)')
583-
ip.compile.reset_compiler_flags()
584-
with tt.AssertNotPrints('0.25'):
585-
ip.run_line_magic('timeit', '-n1 -r1 print(1/4)')
586-
587564
@dec.skipif(execution.profile is None)
588565
def test_prun_special_syntax():
589566
"Test %%prun with IPython special syntax"

IPython/core/tests/test_magic_terminal.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ def check_cpaste(code, should_fail=False):
5757
finally:
5858
sys.stdin = stdin_save
5959

60-
PY31 = sys.version_info[:2] == (3,1)
61-
6260
def test_cpaste():
6361
"""Test cpaste magic"""
6462

@@ -77,13 +75,8 @@ def runf():
7775
],
7876

7977
'fail': ["1 + runf()",
78+
"++ runf()",
8079
]}
81-
82-
# I don't know why this is failing specifically on Python 3.1. I've
83-
# checked it manually interactively, but we don't care enough about 3.1
84-
# to spend time fiddling with the tests, so we just skip it.
85-
if not PY31:
86-
tests['fail'].append("++ runf()")
8780

8881
ip.user_ns['runf'] = runf
8982

IPython/core/tests/test_oinspect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ def test_info():
275275
nt.assert_equal(i['type_name'], 'type')
276276
expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'>
277277
nt.assert_equal(i['base_class'], expted_class)
278-
if sys.version_info > (3,):
279-
nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
278+
nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
280279
fname = __file__
281280
if fname.endswith(".pyc"):
282281
fname = fname[:-1]

IPython/core/tests/test_ultratb.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -313,44 +313,43 @@ def capture_exc(*args, **kwargs):
313313
#----------------------------------------------------------------------------
314314

315315
# module testing (minimal)
316-
if sys.version_info > (3,):
317-
def test_handlers():
318-
def spam(c, d_e):
319-
(d, e) = d_e
320-
x = c + d
321-
y = c * d
322-
foo(x, y)
323-
324-
def foo(a, b, bar=1):
325-
eggs(a, b + bar)
326-
327-
def eggs(f, g, z=globals()):
328-
h = f + g
329-
i = f - g
330-
return h / i
331-
332-
buff = io.StringIO()
333-
334-
buff.write('')
335-
buff.write('*** Before ***')
336-
try:
337-
buff.write(spam(1, (2, 3)))
338-
except:
339-
traceback.print_exc(file=buff)
340-
341-
handler = ColorTB(ostream=buff)
342-
buff.write('*** ColorTB ***')
343-
try:
344-
buff.write(spam(1, (2, 3)))
345-
except:
346-
handler(*sys.exc_info())
347-
buff.write('')
348-
349-
handler = VerboseTB(ostream=buff)
350-
buff.write('*** VerboseTB ***')
351-
try:
352-
buff.write(spam(1, (2, 3)))
353-
except:
354-
handler(*sys.exc_info())
355-
buff.write('')
316+
def test_handlers():
317+
def spam(c, d_e):
318+
(d, e) = d_e
319+
x = c + d
320+
y = c * d
321+
foo(x, y)
322+
323+
def foo(a, b, bar=1):
324+
eggs(a, b + bar)
325+
326+
def eggs(f, g, z=globals()):
327+
h = f + g
328+
i = f - g
329+
return h / i
330+
331+
buff = io.StringIO()
332+
333+
buff.write('')
334+
buff.write('*** Before ***')
335+
try:
336+
buff.write(spam(1, (2, 3)))
337+
except:
338+
traceback.print_exc(file=buff)
339+
340+
handler = ColorTB(ostream=buff)
341+
buff.write('*** ColorTB ***')
342+
try:
343+
buff.write(spam(1, (2, 3)))
344+
except:
345+
handler(*sys.exc_info())
346+
buff.write('')
347+
348+
handler = VerboseTB(ostream=buff)
349+
buff.write('*** VerboseTB ***')
350+
try:
351+
buff.write(spam(1, (2, 3)))
352+
except:
353+
handler(*sys.exc_info())
354+
buff.write('')
356355

IPython/testing/iptest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545

4646
# Enable printing all warnings raise by IPython's modules
4747
warnings.filterwarnings('ignore', message='.*Matplotlib is building the font cache.*', category=UserWarning, module='.*')
48-
if sys.version_info > (3,0):
49-
warnings.filterwarnings('error', message='.*', category=ResourceWarning, module='.*')
48+
warnings.filterwarnings('error', message='.*', category=ResourceWarning, module='.*')
5049
warnings.filterwarnings('error', message=".*{'config': True}.*", category=DeprecationWarning, module='IPy.*')
5150
warnings.filterwarnings('default', message='.*', category=Warning, module='IPy.*')
5251

IPython/testing/skipdoctest.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
"""Decorators marks that a doctest should be skipped, for both python 2 and 3.
1+
"""Decorators marks that a doctest should be skipped.
22
33
The IPython.testing.decorators module triggers various extra imports, including
44
numpy and sympy if they're present. Since this decorator is used in core parts
55
of IPython, it's in a separate module so that running IPython doesn't trigger
66
those imports."""
77

8-
#-----------------------------------------------------------------------------
9-
# Copyright (C) 2009-2011 The IPython Development Team
10-
#
11-
# Distributed under the terms of the BSD License. The full license is in
12-
# the file COPYING, distributed as part of this software.
13-
#-----------------------------------------------------------------------------
8+
# Copyright (C) IPython Development Team
9+
# Distributed under the terms of the Modified BSD License.
1410

15-
#-----------------------------------------------------------------------------
16-
# Imports
17-
#-----------------------------------------------------------------------------
18-
19-
import sys
20-
21-
#-----------------------------------------------------------------------------
22-
# Decorators
23-
#-----------------------------------------------------------------------------
2411

2512
def skip_doctest(f):
2613
"""Decorator - mark a function or method for skipping its doctest.

0 commit comments

Comments
 (0)