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

Skip to content

Commit cf0d493

Browse files
committed
remove Python2/3 specific decorators
1 parent 7851f8a commit cf0d493

6 files changed

Lines changed: 7 additions & 169 deletions

File tree

IPython/core/interactiveshell.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
from IPython.core.prefilter import PrefilterManager
5858
from IPython.core.profiledir import ProfileDir
5959
from IPython.core.usage import default_banner
60-
from IPython.testing.skipdoctest import skip_doctest_py2, skip_doctest
60+
from IPython.testing.skipdoctest import skip_doctest
6161
from IPython.utils import PyColorize
6262
from IPython.utils import io
6363
from IPython.utils import py3compat
@@ -1919,7 +1919,6 @@ def init_completer(self):
19191919
self.set_hook('complete_command', reset_completer, str_key = '%reset')
19201920

19211921

1922-
@skip_doctest_py2
19231922
def complete(self, text, line=None, cursor_pos=None):
19241923
"""Return the completed text and a list of completions.
19251924

IPython/core/oinspect.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
# IPython's own
3232
from IPython.core import page
3333
from IPython.lib.pretty import pretty
34-
from IPython.testing.skipdoctest import skip_doctest_py3
3534
from IPython.utils import PyColorize
3635
from IPython.utils import openpy
3736
from IPython.utils import py3compat
@@ -436,66 +435,6 @@ def pdef(self, obj, oname=''):
436435
else:
437436
print(header,self.format(output), end=' ')
438437

439-
# In Python 3, all classes are new-style, so they all have __init__.
440-
@skip_doctest_py3
441-
def pdoc(self, obj, oname='', formatter=None):
442-
"""Print the docstring for any object.
443-
444-
Optional:
445-
-formatter: a function to run the docstring through for specially
446-
formatted docstrings.
447-
448-
Examples
449-
--------
450-
451-
In [1]: class NoInit:
452-
...: pass
453-
454-
In [2]: class NoDoc:
455-
...: def __init__(self):
456-
...: pass
457-
458-
In [3]: %pdoc NoDoc
459-
No documentation found for NoDoc
460-
461-
In [4]: %pdoc NoInit
462-
No documentation found for NoInit
463-
464-
In [5]: obj = NoInit()
465-
466-
In [6]: %pdoc obj
467-
No documentation found for obj
468-
469-
In [5]: obj2 = NoDoc()
470-
471-
In [6]: %pdoc obj2
472-
No documentation found for obj2
473-
"""
474-
475-
head = self.__head # For convenience
476-
lines = []
477-
ds = getdoc(obj)
478-
if formatter:
479-
ds = formatter(ds).get('plain/text', ds)
480-
if ds:
481-
lines.append(head("Class docstring:"))
482-
lines.append(indent(ds))
483-
if inspect.isclass(obj) and hasattr(obj, '__init__'):
484-
init_ds = getdoc(obj.__init__)
485-
if init_ds is not None:
486-
lines.append(head("Init docstring:"))
487-
lines.append(indent(init_ds))
488-
elif hasattr(obj,'__call__'):
489-
call_ds = getdoc(obj.__call__)
490-
if call_ds:
491-
lines.append(head("Call docstring:"))
492-
lines.append(indent(call_ds))
493-
494-
if not lines:
495-
self.noinfo('documentation',oname)
496-
else:
497-
page.page('\n'.join(lines))
498-
499438
def psource(self, obj, oname=''):
500439
"""Print the source code for an object."""
501440

IPython/lib/tests/test_pretty.py

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@
1212
import nose.tools as nt
1313

1414
from IPython.lib import pretty
15-
from IPython.testing.decorators import (skip_without, py2_only, py3_only)
16-
17-
from IPython.utils.py3compat import PY3, unicode_to_str
15+
from IPython.testing.decorators import skip_without
1816

19-
if PY3:
20-
from io import StringIO
21-
else:
22-
from StringIO import StringIO
17+
from io import StringIO
2318

2419

2520
class MyList(object):
@@ -245,7 +240,7 @@ def test_metaclass_repr():
245240

246241
def test_unicode_repr():
247242
u = u"üniçodé"
248-
ustr = unicode_to_str(u)
243+
ustr = u
249244

250245
class C(object):
251246
def __repr__(self):
@@ -276,83 +271,6 @@ def type_pprint_wrapper(obj, p, cycle):
276271
nt.assert_true(type_pprint_wrapper.called)
277272

278273

279-
# This is only run on Python 2 because in Python 3 the language prevents you
280-
# from setting a non-unicode value for __qualname__ on a metaclass, and it
281-
# doesn't respect the descriptor protocol if you subclass unicode and implement
282-
# __get__.
283-
@py2_only
284-
def test_fallback_to__name__on_type():
285-
# Test that we correctly repr types that have non-string values for
286-
# __qualname__ by falling back to __name__
287-
288-
class Type(object):
289-
__qualname__ = 5
290-
291-
# Test repring of the type.
292-
stream = StringIO()
293-
printer = pretty.RepresentationPrinter(stream)
294-
295-
printer.pretty(Type)
296-
printer.flush()
297-
output = stream.getvalue()
298-
299-
# If __qualname__ is malformed, we should fall back to __name__.
300-
expected = '.'.join([__name__, Type.__name__])
301-
nt.assert_equal(output, expected)
302-
303-
# Clear stream buffer.
304-
stream.buf = ''
305-
306-
# Test repring of an instance of the type.
307-
instance = Type()
308-
printer.pretty(instance)
309-
printer.flush()
310-
output = stream.getvalue()
311-
312-
# Should look like:
313-
# <IPython.lib.tests.test_pretty.Type at 0x7f7658ae07d0>
314-
prefix = '<' + '.'.join([__name__, Type.__name__]) + ' at 0x'
315-
nt.assert_true(output.startswith(prefix))
316-
317-
318-
@py2_only
319-
def test_fail_gracefully_on_bogus__qualname__and__name__():
320-
# Test that we correctly repr types that have non-string values for both
321-
# __qualname__ and __name__
322-
323-
class Meta(type):
324-
__name__ = 5
325-
326-
class Type(object):
327-
__metaclass__ = Meta
328-
__qualname__ = 5
329-
330-
stream = StringIO()
331-
printer = pretty.RepresentationPrinter(stream)
332-
333-
printer.pretty(Type)
334-
printer.flush()
335-
output = stream.getvalue()
336-
337-
# If we can't find __name__ or __qualname__ just use a sentinel string.
338-
expected = '.'.join([__name__, '<unknown type>'])
339-
nt.assert_equal(output, expected)
340-
341-
# Clear stream buffer.
342-
stream.buf = ''
343-
344-
# Test repring of an instance of the type.
345-
instance = Type()
346-
printer.pretty(instance)
347-
printer.flush()
348-
output = stream.getvalue()
349-
350-
# Should look like:
351-
# <IPython.lib.tests.test_pretty.<unknown type> at 0x7f7658ae07d0>
352-
prefix = '<' + '.'.join([__name__, '<unknown type>']) + ' at 0x'
353-
nt.assert_true(output.startswith(prefix))
354-
355-
356274
def test_collections_defaultdict():
357275
# Create defaultdicts with cycles
358276
a = defaultdict()
@@ -441,7 +359,6 @@ class MyCounter(Counter):
441359
for obj, expected in cases:
442360
nt.assert_equal(pretty.pretty(obj), expected)
443361

444-
@py3_only
445362
def test_mappingproxy():
446363
MP = types.MappingProxyType
447364
underlying_dict = {}

IPython/testing/decorators.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ def skip_file_no_x11(name):
334334

335335
skip_known_failure = knownfailureif(True,'This test is known to fail')
336336

337-
known_failure_py3 = knownfailureif(sys.version_info[0] >= 3,
338-
'This test is known to fail on Python 3.')
339-
340-
py2_only = skipif(PY3, "This test only runs on Python 2.")
341-
py3_only = skipif(PY2, "This test only runs on Python 3.")
342-
343337
# A null 'decorator', useful to make more readable code that needs to pick
344338
# between different decorators based on OS or other conditions
345339
null_deco = lambda f: f

IPython/testing/skipdoctest.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,3 @@ def skip_doctest(f):
1717
etc."""
1818
f.skip_doctest = True
1919
return f
20-
21-
22-
def skip_doctest_py3(f):
23-
"""Decorator - skip the doctest under Python 3."""
24-
f.skip_doctest = (sys.version_info[0] >= 3)
25-
return f
26-
27-
def skip_doctest_py2(f):
28-
"""Decorator - skip the doctest under Python 3."""
29-
f.skip_doctest = (sys.version_info[0] < 3)
30-
return f

IPython/utils/text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Python 2 backport
2121
from pathlib2 import Path
2222

23-
from IPython.testing.skipdoctest import skip_doctest_py3, skip_doctest
23+
from IPython.testing.skipdoctest import skip_doctest
2424
from IPython.utils import py3compat
2525

2626
# datetime.strftime date format for ipython
@@ -517,7 +517,7 @@ def get_field(self, name, args, kwargs):
517517
# inside [], so EvalFormatter can handle slicing. Once we only support 3.4 and
518518
# above, it should be possible to remove FullEvalFormatter.
519519

520-
@skip_doctest_py3
520+
@skip_doctest
521521
class FullEvalFormatter(Formatter):
522522
"""A String Formatter that allows evaluation of simple expressions.
523523
@@ -574,7 +574,7 @@ def vformat(self, format_string, args, kwargs):
574574
return u''.join(py3compat.cast_unicode(s) for s in result)
575575

576576

577-
@skip_doctest_py3
577+
@skip_doctest
578578
class DollarFormatter(FullEvalFormatter):
579579
"""Formatter allowing Itpl style $foo replacement, for names and attribute
580580
access only. Standard {foo} replacement also works, and allows full

0 commit comments

Comments
 (0)