Skip to content

Commit a83e99b

Browse files
SylvainCorlayCarreau
authored andcommitted
Remove uses of ipython_genutils.py3compat
1 parent 6b72191 commit a83e99b

10 files changed

+67
-53
lines changed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878

7979
install_requires = setuptools_args['install_requires'] = [
8080
'ipython_genutils',
81+
'six',
8182
'decorator',
8283
]
8384

traitlets/config/application.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
from ipython_genutils.importstring import import_item
2727
from ipython_genutils.text import indent, wrap_paragraphs, dedent
2828
from ipython_genutils import py3compat
29-
from ipython_genutils.py3compat import string_types, iteritems
29+
30+
import six
31+
from six import iteritems
3032

3133
#-----------------------------------------------------------------------------
3234
# Descriptions for the various sections
@@ -162,7 +164,7 @@ def _classes_inc_parents(self):
162164
def _log_level_changed(self, change):
163165
"""Adjust the log level when log_level is set."""
164166
new = change['new']
165-
if isinstance(new, string_types):
167+
if isinstance(new, six.string_types):
166168
new = getattr(logging, new)
167169
self.log_level = new
168170
self.log.setLevel(new)
@@ -228,10 +230,10 @@ def _log_default(self):
228230
def _flags_changed(self, change):
229231
"""ensure flags dict is valid"""
230232
new = change['new']
231-
for key, value in new.items():
233+
for key, value in iteritems(new):
232234
assert len(value) == 2, "Bad flag: %r:%s" % (key, value)
233235
assert isinstance(value[0], (dict, Config)), "Bad flag: %r:%s" % (key, value)
234-
assert isinstance(value[1], string_types), "Bad flag: %r:%s" % (key, value)
236+
assert isinstance(value[1], six.string_types), "Bad flag: %r:%s" % (key, value)
235237

236238

237239
# subcommands for launching other applications
@@ -415,7 +417,7 @@ def initialize_subcommand(self, subc, argv=None):
415417
"""Initialize a subcommand with argv."""
416418
subapp,help = self.subcommands.get(subc)
417419

418-
if isinstance(subapp, string_types):
420+
if isinstance(subapp, six.string_types):
419421
subapp = import_item(subapp)
420422

421423
# clear existing instances

traitlets/config/configurable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .loader import Config, LazyConfigValue, _is_section_key
1313
from traitlets.traitlets import HasTraits, Instance, observe, observe_compat, default
1414
from ipython_genutils.text import indent, dedent, wrap_paragraphs
15-
from ipython_genutils.py3compat import iteritems
15+
from six import iteritems
1616

1717

1818
#-----------------------------------------------------------------------------

traitlets/config/loader.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ipython_genutils.path import filefind
1717
from ipython_genutils import py3compat
1818
from ipython_genutils.encoding import DEFAULT_ENCODING
19-
from ipython_genutils.py3compat import unicode_type, iteritems
19+
from six import text_type, iteritems
2020
from traitlets.traitlets import HasTraits, List, Any
2121

2222
#-----------------------------------------------------------------------------
@@ -603,7 +603,7 @@ def _decode_argv(self, argv, enc=None):
603603
if enc is None:
604604
enc = DEFAULT_ENCODING
605605
for arg in argv:
606-
if not isinstance(arg, unicode_type):
606+
if not isinstance(arg, text_type):
607607
# only decode if not already decoded
608608
arg = arg.decode(enc)
609609
uargv.append(arg)
@@ -793,9 +793,9 @@ def _add_arguments(self, aliases=None, flags=None):
793793
else:
794794
nargs = None
795795
if len(key) is 1:
796-
paa('-'+key, '--'+key, type=unicode_type, dest=value, nargs=nargs)
796+
paa('-'+key, '--'+key, type=text_type, dest=value, nargs=nargs)
797797
else:
798-
paa('--'+key, type=unicode_type, dest=value, nargs=nargs)
798+
paa('--'+key, type=text_type, dest=value, nargs=nargs)
799799
for key, (value, help) in iteritems(flags):
800800
if key in self.aliases:
801801
#

traitlets/config/manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import json
88
import os
99

10+
from six import PY3
1011
from traitlets.config import LoggingConfigurable
11-
from ipython_genutils.py3compat import PY3
1212
from traitlets.traitlets import Unicode
1313

1414

traitlets/config/tests/test_configurable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
from traitlets.config.loader import Config
25-
from ipython_genutils.py3compat import PY3
25+
from six import PY3
2626

2727
from ...tests._warnings import expected_warnings
2828

traitlets/tests/test_traitlets.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ._warnings import expected_warnings
1414

1515
from nose2.compat import unittest
16-
from unittest import TestCase
16+
from unittest import TestCase, skipif
1717
from nose2.tools.such import helper as testhelper
1818

1919
from traitlets import (
@@ -24,7 +24,8 @@
2424
ForwardDeclaredType, ForwardDeclaredInstance, validate, observe, default,
2525
observe_compat, BaseDescriptor, HasDescriptors,
2626
)
27-
from ipython_genutils import py3compat
27+
28+
import six
2829

2930
def change_dict(*ordered_values):
3031
change_names = ('name', 'old', 'new', 'owner', 'type')
@@ -1143,30 +1144,30 @@ class TestInt(TraitTestBase):
11431144
_bad_values = ['ten', u'ten', [10], {'ten': 10}, (10,), None, 1j,
11441145
10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L',
11451146
u'-10L', u'10.1', u'-10.1', '10', '-10', u'10', -200]
1146-
if not py3compat.PY3:
1147+
if not six.PY3:
11471148
_bad_values.extend([long(10), long(-10), 10*sys.maxint, -10*sys.maxint])
11481149

11491150

11501151
class LongTrait(HasTraits):
11511152

1152-
value = Long(99 if py3compat.PY3 else long(99))
1153+
value = Long(99 if six.PY3 else long(99))
11531154

11541155
class TestLong(TraitTestBase):
11551156

11561157
obj = LongTrait()
11571158

1158-
_default_value = 99 if py3compat.PY3 else long(99)
1159+
_default_value = 99 if six.PY3 else long(99)
11591160
_good_values = [10, -10]
11601161
_bad_values = ['ten', u'ten', [10], {'ten': 10},(10,),
11611162
None, 1j, 10.1, -10.1, '10', '-10', '10L', '-10L', '10.1',
11621163
'-10.1', u'10', u'-10', u'10L', u'-10L', u'10.1',
11631164
u'-10.1']
1164-
if not py3compat.PY3:
1165+
if not six.PY3:
11651166
# maxint undefined on py3, because int == long
11661167
_good_values.extend([long(10), long(-10), 10*sys.maxint, -10*sys.maxint])
11671168
_bad_values.extend([[long(10)], (long(10),)])
11681169

1169-
@unittest.skipIf(py3compat.PY3, "not relevant on py3")
1170+
@skipif(six.PY3, "not relevant on py3")
11701171
def test_cast_small(self):
11711172
"""Long casts ints to long"""
11721173
self.obj.value = 10
@@ -1183,10 +1184,10 @@ class TestInteger(TestLong):
11831184
def coerce(self, n):
11841185
return int(n)
11851186

1186-
@unittest.skipIf(py3compat.PY3, "not relevant on py3")
1187+
@skipif(six.PY3, "not relevant on py3")
11871188
def test_cast_small(self):
11881189
"""Integer casts small longs to int"""
1189-
if py3compat.PY3:
1190+
if six.PY3:
11901191
raise unittest.SkipTest("not relevant on py3")
11911192

11921193
self.obj.value = long(100)
@@ -1206,7 +1207,7 @@ class TestFloat(TraitTestBase):
12061207
_bad_values = ['ten', u'ten', [10], {'ten': 10}, (10,), None,
12071208
1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10',
12081209
u'-10', u'10L', u'-10L', u'10.1', u'-10.1', 201.0]
1209-
if not py3compat.PY3:
1210+
if not six.PY3:
12101211
_bad_values.extend([long(10), long(-10)])
12111212

12121213

@@ -1222,7 +1223,7 @@ class TestComplex(TraitTestBase):
12221223
_good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j,
12231224
10.1j, 10.1+10.1j, 10.1-10.1j]
12241225
_bad_values = [u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None]
1225-
if not py3compat.PY3:
1226+
if not six.PY3:
12261227
_bad_values.extend([long(10), long(-10)])
12271228

12281229

@@ -1239,7 +1240,7 @@ class TestBytes(TraitTestBase):
12391240
b'-10L', b'10.1', b'-10.1', b'string']
12401241
_bad_values = [10, -10, 10.1, -10.1, 1j, [10],
12411242
['ten'],{'ten': 10},(10,), None, u'string']
1242-
if not py3compat.PY3:
1243+
if not six.PY3:
12431244
_bad_values.extend([long(10), long(-10)])
12441245

12451246

@@ -1256,7 +1257,7 @@ class TestUnicode(TraitTestBase):
12561257
'-10.1', '', u'', 'string', u'string', u"€"]
12571258
_bad_values = [10, -10, 10.1, -10.1, 1j,
12581259
[10], ['ten'], [u'ten'], {'ten': 10},(10,), None]
1259-
if not py3compat.PY3:
1260+
if not six.PY3:
12601261
_bad_values.extend([long(10), long(-10)])
12611262

12621263

0 commit comments

Comments
 (0)