diff options
author | Emile Anclin <emile.anclin@logilab.fr> | 2010-11-15 12:11:37 +0100 |
---|---|---|
committer | Emile Anclin <emile.anclin@logilab.fr> | 2010-11-15 12:11:37 +0100 |
commit | 135b4141389138d95ad2c1a83a6a706f9758ceb6 (patch) | |
tree | 130bce997d5d6562db51f940f186f427b1779ee6 | |
parent | 2575a944af5839cf1bbafbdfe7f7f55478020014 (diff) | |
download | logilab-common-135b4141389138d95ad2c1a83a6a706f9758ceb6.tar.gz |
2to3 has some more usable fixers
-rw-r--r-- | clcommands.py | 3 | ||||
-rw-r--r-- | cli.py | 5 | ||||
-rw-r--r-- | configuration.py | 4 | ||||
-rw-r--r-- | daemon.py | 2 | ||||
-rw-r--r-- | table.py | 5 | ||||
-rw-r--r-- | test/unittest_modutils.py | 12 | ||||
-rw-r--r-- | testlib.py | 2 |
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: @@ -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) @@ -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: @@ -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']]) @@ -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: |