summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-11-15 12:11:37 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-11-15 12:11:37 +0100
commit135b4141389138d95ad2c1a83a6a706f9758ceb6 (patch)
tree130bce997d5d6562db51f940f186f427b1779ee6
parent2575a944af5839cf1bbafbdfe7f7f55478020014 (diff)
downloadlogilab-common-135b4141389138d95ad2c1a83a6a706f9758ceb6.tar.gz
2to3 has some more usable fixers
-rw-r--r--clcommands.py3
-rw-r--r--cli.py5
-rw-r--r--configuration.py4
-rw-r--r--daemon.py2
-rw-r--r--table.py5
-rw-r--r--test/unittest_modutils.py12
-rw-r--r--testlib.py2
7 files changed, 15 insertions, 18 deletions
diff --git a/clcommands.py b/clcommands.py
index 19a6c07..d061dce 100644
--- a/clcommands.py
+++ b/clcommands.py
@@ -277,8 +277,7 @@ class ListCommandsCommand(Command):
print '--help'
print '--' + optname
else:
- commands = _COMMANDS.keys()
- commands.sort()
+ commands = sorted(_COMMANDS.keys())
for command in commands:
cmd = _COMMANDS[command]
if not cmd.hidden:
diff --git a/cli.py b/cli.py
index 6c77bc4..f3b2bfd 100644
--- a/cli.py
+++ b/cli.py
@@ -105,7 +105,7 @@ class CLIHelper:
def run(self):
"""loop on user input, exit on EOF"""
- while 1:
+ while True:
try:
line = raw_input('>>> ')
except EOFError:
@@ -171,8 +171,7 @@ class CLIHelper:
elif command is None or command not in self._topics:
print _("Use help <topic> or help <command>.")
print _("Available topics are:")
- topics = self._topics.keys()
- topics.sort()
+ topics = sorted(self._topics.keys())
for topic in topics:
print '\t', topic
print
diff --git a/configuration.py b/configuration.py
index 2de850f..54a0a65 100644
--- a/configuration.py
+++ b/configuration.py
@@ -815,13 +815,13 @@ class OptionsProviderMixIn(object):
opt = self.option_name(opt, optdict)
_list = getattr(self.config, opt, None)
if _list is None:
- if type(value) in (type(()), type([])):
+ if isinstance(value, (list, tuple)):
_list = value
elif value is not None:
_list = []
_list.append(value)
setattr(self.config, opt, _list)
- elif type(_list) is type(()):
+ elif isinstance(_list, tuple):
setattr(self.config, opt, _list + (value,))
else:
_list.append(value)
diff --git a/daemon.py b/daemon.py
index bce770f..78847d1 100644
--- a/daemon.py
+++ b/daemon.py
@@ -111,7 +111,7 @@ If it i not the case, remove the file %s''' % (self.name, self._pid_file))
if self.delay < 0:
self.delay = -self.delay
time.sleep(self.delay)
- while 1:
+ while True:
try:
self._run()
except Exception, ex:
diff --git a/table.py b/table.py
index a81203d..398f1fc 100644
--- a/table.py
+++ b/table.py
@@ -100,10 +100,9 @@ class Table(object):
method should be in ('asc', 'desc')
"""
- sort_list = [(row[col_index], row, row_name)
- for row, row_name in zip(self.data, self.row_names)]
+ sort_list = sorted([(row[col_index], row, row_name)
+ for row, row_name in zip(self.data, self.row_names)])
# Sorting sort_list will sort according to col_index
- sort_list.sort()
# If we want reverse sort, then reverse list
if method.lower() == 'desc':
sort_list.reverse()
diff --git a/test/unittest_modutils.py b/test/unittest_modutils.py
index 42cd7d5..709c7f8 100644
--- a/test/unittest_modutils.py
+++ b/test/unittest_modutils.py
@@ -216,11 +216,11 @@ class get_modules_tc(TestCase):
"""
import data.find_test as data
mod_path = ("data", 'find_test')
- modules = modutils.get_modules(path.join(*mod_path), data.__path__[0])
- modules.sort()
+ modules = sorted(modutils.get_modules(path.join(*mod_path),
+ data.__path__[0]))
self.assertSetEqual(set(modules),
- set([ '.'.join(mod_path + (mod, )) for mod in 'module', 'module2',
- 'noendingnewline', 'nonregr']))
+ set([ '.'.join(mod_path + (mod, )) for mod in ('module', 'module2',
+ 'noendingnewline', 'nonregr')]))
class get_modules_files_tc(TestCase):
@@ -230,8 +230,8 @@ class get_modules_files_tc(TestCase):
in subdirectories
"""
import data
- modules = modutils.get_module_files(path.join(DATADIR, 'find_test'), data.__path__[0])
- modules.sort()
+ modules = sorted(modutils.get_module_files(path.join(DATADIR, 'find_test'),
+ data.__path__[0]))
self.assertEqual(modules,
[path.join(DATADIR, 'find_test', x) for x in ['__init__.py', 'module.py', 'module2.py', 'noendingnewline.py', 'nonregr.py']])
diff --git a/testlib.py b/testlib.py
index f229ba0..ba01788 100644
--- a/testlib.py
+++ b/testlib.py
@@ -177,7 +177,7 @@ def run_tests(tests, quiet, verbose, runner=None, capture=0):
print '-'*80
print "Executing", test
result = run_test(test, verbose, runner, capture)
- if type(result) is type(''):
+ if isinstance(result, str):
# an unexpected error occurred
skipped.append( (test, result))
else: