[PATCH 09 of 11 logilab-common] Please the flake8 god

Laurent Peuch cortex at worlddomination.be
Wed Apr 1 16:20:10 CEST 2020


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1584617074 -3600
#      Thu Mar 19 12:24:34 2020 +0100
# Node ID ce0cfacc08238cf77231565422395dccc6e938e3
# Parent  e3ee44e0c9701d5ff5789c4f1535cccf5f8a91f9
# Available At https://hg.logilab.org/users/lpeuch/logilab-common
#              hg pull https://hg.logilab.org/users/lpeuch/logilab-common -r ce0cfacc0823
# EXP-Topic types-annotations-and-cleaning
Please the flake8 god

diff --git a/logilab/common/cache.py b/logilab/common/cache.py
--- a/logilab/common/cache.py
+++ b/logilab/common/cache.py
@@ -27,7 +27,7 @@ deletion of entries.
 from threading import Lock
 
 from logilab.common.decorators import locked
-from typing import Union, TypeVar, List
+from typing import TypeVar, List
 
 _marker = object()
 
diff --git a/logilab/common/clcommands.py b/logilab/common/clcommands.py
--- a/logilab/common/clcommands.py
+++ b/logilab/common/clcommands.py
@@ -103,7 +103,7 @@ class CommandLine(dict):
 
     def register(self, cls, force=False):
         """register the given :class:`Command` subclass"""
-        assert not self.check_duplicated_command or force or not cls.name in self, (
+        assert not self.check_duplicated_command or force or cls.name not in self, (
             "a command %s is already defined" % cls.name
         )
         self[cls.name] = cls
diff --git a/logilab/common/compat.py b/logilab/common/compat.py
--- a/logilab/common/compat.py
+++ b/logilab/common/compat.py
@@ -29,14 +29,12 @@ See another compatibility snippets from 
 
 __docformat__ = "restructuredtext en"
 
-import os
 import sys
 import types
-from warnings import warn
 from typing import Union
 
 # not used here, but imported to preserve API
-import builtins
+import builtins  # noqa
 
 
 def str_to_bytes(string):
@@ -65,14 +63,14 @@ else:
 if sys.version_info < (3, 0):
     from cStringIO import StringIO
 
-    FileIO = file
+    FileIO = file  # noqa
     BytesIO = StringIO
-    reload = reload
+    reload = reload  # noqa
 else:
-    from io import FileIO, BytesIO, StringIO
-    from imp import reload
+    from io import StringIO, FileIO  # noqa
+    from imp import reload  # noqa
 
-from logilab.common.deprecation import deprecated
+from logilab.common.deprecation import deprecated  # noqa
 
 # Other projects import these from here, keep providing them for
 # backwards compat
diff --git a/logilab/common/configuration.py b/logilab/common/configuration.py
--- a/logilab/common/configuration.py
+++ b/logilab/common/configuration.py
@@ -126,8 +126,7 @@ from os.path import exists, expanduser
 from optparse import OptionGroup
 from copy import copy
 from _io import StringIO, TextIOWrapper
-from mypy_extensions import NoReturn
-from typing import Any, Optional, Union, Dict, List, Tuple, Iterator, Callable, Sequence
+from typing import Any, Optional, Union, Dict, List, Tuple, Iterator, Callable
 from warnings import warn
 
 import configparser as cp
@@ -168,7 +167,7 @@ def _get_encoding(encoding: Optional[str
 def choice_validator(optdict: Dict[str, Any], name: str, value: str) -> str:
     """validate and return a converted value for option of type 'choice'
     """
-    if not value in optdict["choices"]:
+    if value not in optdict["choices"]:
         msg = "option %s: invalid value: %r, should be in %s"
         raise optik_ext.OptionValueError(msg % (name, value, optdict["choices"]))
     return value
@@ -180,7 +179,7 @@ def multiple_choice_validator(optdict: D
     choices = optdict["choices"]
     values = optik_ext.check_csv(None, name, value)
     for value in values:
-        if not value in choices:
+        if value not in choices:
             msg = "option %s: invalid value: %r, should be in %s"
             raise optik_ext.OptionValueError(msg % (name, value, choices))
     return values
@@ -269,7 +268,7 @@ def _call_validator(
             return VALIDATORS[opttype](value)
         except optik_ext.OptionValueError:
             raise
-        except:
+        except Exception:
             raise optik_ext.OptionValueError(
                 "%s value (%r) should be of type %s" % (option, value, opttype)
             )
@@ -638,7 +637,7 @@ class OptionsManagerMixIn(object):
             del optdict["short"]
         # cleanup option definition dict before giving it to optik
         for key in list(optdict.keys()):
-            if not key in self._optik_option_attrs:
+            if key not in self._optik_option_attrs:
                 optdict.pop(key)
         return args, optdict
 
@@ -682,7 +681,7 @@ class OptionsManagerMixIn(object):
                 options = [(n, d, v) for (n, d, v) in options if d.get("type") is not None]
                 if not options:
                     continue
-                if not section in sections:
+                if section not in sections:
                     sections.append(section)
                 alloptions = options_by_section.setdefault(section, [])
                 alloptions += options
@@ -773,7 +772,7 @@ class OptionsManagerMixIn(object):
             for section, option, optdict in provider.all_options():
                 if onlysection is not None and section != onlysection:
                     continue
-                if not "type" in optdict:
+                if "type" not in optdict:
                     # ignore action without type (callback, store_true...)
                     continue
                 provider.input_option(option, optdict, inputlevel)
@@ -1079,7 +1078,7 @@ class ConfigurationMixIn(OptionsManagerM
                     gdef = (optdict["group"].upper(), "")
                 except KeyError:
                     continue
-                if not gdef in self.option_groups:
+                if gdef not in self.option_groups:
                     self.option_groups.append(gdef)
         self.register_options_provider(self, own_group=False)
 
@@ -1225,7 +1224,7 @@ def read_old_config(newconfig, changes, 
             newconfig[optname] = newvalue
             done.add(optname)
     for optname, optdef in newconfig.options:
-        if optdef.get("type") and not optname in done:
+        if optdef.get("type") and optname not in done:
             newconfig.set_option(optname, oldconfig[optname], optdict=optdef)
 
 
diff --git a/logilab/common/daemon.py b/logilab/common/daemon.py
--- a/logilab/common/daemon.py
+++ b/logilab/common/daemon.py
@@ -21,9 +21,6 @@
 
 import os
 import errno
-import signal
-import sys
-import time
 import warnings
 
 
diff --git a/logilab/common/date.py b/logilab/common/date.py
--- a/logilab/common/date.py
+++ b/logilab/common/date.py
@@ -27,7 +27,7 @@ from locale import getlocale, LC_TIME
 from datetime import date, time, datetime, timedelta
 from time import strptime as time_strptime
 from calendar import monthrange, timegm
-from typing import Union, List, Any, Iterator, Optional, Generator
+from typing import Union, List, Any, Optional, Generator
 
 
 try:
@@ -213,14 +213,6 @@ def date_range(
 ONEDAY: timedelta = timedelta(days=1)
 ONEWEEK: timedelta = timedelta(days=7)
 
-try:
-    strptime = datetime.strptime
-except AttributeError:  # py < 2.5
-    from time import strptime as time_strptime
-
-    def strptime(value, format):
-        return datetime(*time_strptime(value, format)[:6])
-
 
 def strptime_time(value, format="%H:%M"):
     return time(*time_strptime(value, format)[3:6])
@@ -315,7 +307,7 @@ def ustrftime(somedate: datetime, fmt: s
         try:
             if sys.version_info < (3, 0):
                 encoding = getlocale(LC_TIME)[1] or "ascii"
-                return unicode(somedate.strftime(str(fmt)), encoding)
+                return str(somedate.strftime(str(fmt)), encoding)
             else:
                 return somedate.strftime(fmt)
         except ValueError:
@@ -332,7 +324,7 @@ def ustrftime(somedate: datetime, fmt: s
             if isinstance(somedate, datetime):
                 fields.update({"H": somedate.hour, "M": somedate.minute, "S": somedate.second})
             fmt = re.sub("%([YmdHMS])", r"%(\1)02d", fmt)
-            return unicode(fmt) % fields
+            return str(fmt) % fields
 
 
 def utcdatetime(dt: datetime) -> datetime:
diff --git a/logilab/common/debugger.py b/logilab/common/debugger.py
--- a/logilab/common/debugger.py
+++ b/logilab/common/debugger.py
@@ -39,7 +39,6 @@ except ImportError:
     # conditional import
     readline = None  # type: ignore
 import os
-import os.path as osp
 import sys
 from pdb import Pdb
 import inspect
@@ -186,7 +185,7 @@ class Debugger(Pdb):
                 ret = ret + self.get_class_members(base)
         return ret
 
-    ## specific / overridden commands
+    # specific / overridden commands
     def do_list(self, arg):
         """overrides default list command to display the surrounding block
         instead of 5 lines of context
diff --git a/logilab/common/decorators.py b/logilab/common/decorators.py
--- a/logilab/common/decorators.py
+++ b/logilab/common/decorators.py
@@ -21,11 +21,8 @@ from __future__ import print_function
 
 __docformat__ = "restructuredtext en"
 
-import sys
-import types
 from time import process_time, time
 from inspect import isgeneratorfunction
-from mypy_extensions import NoReturn
 from typing import Any, Optional, Callable, Union
 
 from inspect import getfullargspec
@@ -81,7 +78,7 @@ class _SingleValueCache(object):
         try:
             wrapped.__doc__ = self.callable.__doc__
             wrapped.__name__ = self.callable.__name__
-        except:
+        except Exception:
             pass
         return wrapped
 
diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py
--- a/logilab/common/deprecation.py
+++ b/logilab/common/deprecation.py
@@ -19,7 +19,6 @@
 
 __docformat__ = "restructuredtext en"
 
-import sys
 from warnings import warn
 
 from logilab.common.changelog import Version
diff --git a/logilab/common/fileutils.py b/logilab/common/fileutils.py
--- a/logilab/common/fileutils.py
+++ b/logilab/common/fileutils.py
@@ -40,7 +40,6 @@ from typing import Optional, List, Tuple
 from _io import TextIOWrapper
 
 from logilab.common import STD_BLACKLIST as BASE_BLACKLIST, IGNORED_EXTENSIONS
-from logilab.common.shellutils import find
 from logilab.common.deprecation import deprecated
 from logilab.common.compat import FileIO
 
diff --git a/logilab/common/graph.py b/logilab/common/graph.py
--- a/logilab/common/graph.py
+++ b/logilab/common/graph.py
@@ -30,7 +30,7 @@ import sys
 import tempfile
 import codecs
 import errno
-from typing import Dict, List, Tuple, Union, Any, Optional, Set, TypeVar, Iterable
+from typing import Dict, List, Tuple, Optional, Set, TypeVar, Iterable
 
 
 def escape(value):
diff --git a/logilab/common/modutils.py b/logilab/common/modutils.py
--- a/logilab/common/modutils.py
+++ b/logilab/common/modutils.py
@@ -39,18 +39,20 @@ from os.path import (
     isdir,
     dirname,
     exists,
-    basename,
     expanduser,
     normcase,
     realpath,
 )
 from imp import find_module, load_module, C_BUILTIN, PY_COMPILED, PKG_DIRECTORY
-from distutils.sysconfig import get_config_var, get_python_lib
+from distutils.sysconfig import get_python_lib
 from distutils.errors import DistutilsPlatformError
 from typing import Dict, List, Optional, Any, Tuple, Union, Sequence
 from types import ModuleType
 from _frozen_importlib_external import FileFinder
 
+from logilab.common import STD_BLACKLIST, _handle_blacklist
+from logilab.common.deprecation import deprecated
+
 try:
     import zipimport
 except ImportError:
@@ -60,9 +62,6 @@ except ImportError:
 
 ZIPFILE = object()
 
-from logilab.common import STD_BLACKLIST, _handle_blacklist
-from logilab.common.deprecation import deprecated
-
 # Notes about STD_LIB_DIR
 # Consider arch-specific installation for STD_LIB_DIR definition
 # :mod:`distutils.sysconfig` contains to much hardcoded values to rely on
@@ -108,7 +107,7 @@ class LazyObject(object):
     def __getattribute__(self, attr):
         try:
             return super(LazyObject, self).__getattribute__(attr)
-        except AttributeError as ex:
+        except AttributeError:
             return getattr(self._getobj(), attr)
 
     def __call__(self, *args, **kwargs):
@@ -422,7 +421,7 @@ def get_modules(
     for directory, dirnames, filenames in os.walk(src_directory):
         _handle_blacklist(blacklist, dirnames, filenames)
         # check for __init__.py
-        if not "__init__.py" in filenames:
+        if "__init__.py" not in filenames:
             dirnames[:] = ()
             continue
         if directory != src_directory:
@@ -458,7 +457,7 @@ def get_module_files(src_directory: str,
     for directory, dirnames, filenames in os.walk(src_directory):
         _handle_blacklist(blacklist, dirnames, filenames)
         # check for __init__.py
-        if not "__init__.py" in filenames:
+        if "__init__.py" not in filenames:
             dirnames[:] = ()
             continue
         for filename in filenames:
@@ -551,7 +550,7 @@ def is_standard_module(
     modname = modname.split(".")[0]
     try:
         filename = file_from_modpath([modname])
-    except ImportError as ex:
+    except ImportError:
         # import failed, i'm probably not so wrong by supposing it's
         # not standard...
         return False
@@ -656,8 +655,8 @@ def _is_namespace(modname: str) -> bool:
     # mypy: Module has no attribute "_namespace_packages"; maybe "fixup_namespace_packages"?"
     # but is still has? or is it a failure from python3 port?
     return (
-        pkg_resources is not None and modname in pkg_resources._namespace_packages
-    )  # type: ignore
+        pkg_resources is not None and modname in pkg_resources._namespace_packages  # type: ignore
+    )
 
 
 def _module_file(
@@ -684,7 +683,7 @@ def _module_file(
         pic = sys.path_importer_cache
         _path = path if path is not None else sys.path
         for __path in _path:
-            if not __path in pic:
+            if __path not in pic:
                 try:
                     pic[__path] = zipimport.zipimporter(__path)
                 except zipimport.ZipImportError:
diff --git a/logilab/common/optik_ext.py b/logilab/common/optik_ext.py
--- a/logilab/common/optik_ext.py
+++ b/logilab/common/optik_ext.py
@@ -58,11 +58,10 @@ from os.path import exists
 from logilab.common import attrdict
 
 from typing import Any, Union, List, Optional, Tuple, Dict
-from optparse import Values, IndentedHelpFormatter, OptionGroup
 from _io import StringIO
 
 # python >= 2.3
-from optparse import (
+from optparse import (  # noqa
     OptionParser as BaseParser,
     Option as BaseOption,
     OptionGroup,
@@ -71,8 +70,8 @@ from optparse import (
     OptionError,
     Values,
     HelpFormatter,
+    SUPPRESS_HELP,
     NO_DEFAULT,
-    SUPPRESS_HELP,
 )
 
 try:
@@ -179,7 +178,7 @@ def check_date(option, opt, value):
 
 def check_color(option, opt, value):
     """check a color value and returns it
-    /!\ does *not* check color labels (like 'red', 'green'), only
+    /!\\ does *not* check color labels (like 'red', 'green'), only
     checks hexadecimal forms
     """
     # Case (1) : color label, we trust the end-user
@@ -257,9 +256,9 @@ class Option(BaseOption):
             elif not isinstance(self.choices, (tuple, list)):  # type: ignore
                 raise OptionError(
                     "choices must be a list of strings ('%s' supplied)"
-                    % str(type(self.choices)).split("'")[1],
+                    % str(type(self.choices)).split("'")[1],  # type: ignore
                     self,
-                )  # type: ignore
+                )
         elif self.choices is not None:  # type: ignore
             raise OptionError("must not supply choices for type %r" % self.type, self)
 
@@ -331,8 +330,8 @@ def level_options(group: BaseParser, out
     return [
         option
         for option in group.option_list
-        if (getattr(option, "level", 0) or 0) <= outputlevel and not option.help is SUPPRESS_HELP
-    ]  # type: ignore
+        if (getattr(option, "level", 0) or 0) <= outputlevel and option.help is not SUPPRESS_HELP  # type: ignore  # noqa
+    ]
 
 
 def format_option_help(self, formatter):
@@ -408,7 +407,7 @@ class ManHelpFormatter(HelpFormatter):
         return '.TH %s %s "%s" %s' % (pgm, section, date, pgm)
 
     def format_short_description(self, pgm: str, short_desc: str) -> str:
-        return """.SH NAME
+        return r""".SH NAME
 .B %s
 \- %s
 """ % (
diff --git a/logilab/common/optparser.py b/logilab/common/optparser.py
--- a/logilab/common/optparser.py
+++ b/logilab/common/optparser.py
@@ -35,15 +35,15 @@ from __future__ import print_function
 
 from warnings import warn
 
+import sys
+import optparse
+
 warn(
     "lgc.optparser module is deprecated, use lgc.clcommands instead",
     DeprecationWarning,
     stacklevel=2,
 )
 
-import sys
-import optparse
-
 
 class OptionParser(optparse.OptionParser):
     def __init__(self, *args, **kwargs):
diff --git a/logilab/common/pytest.py b/logilab/common/pytest.py
--- a/logilab/common/pytest.py
+++ b/logilab/common/pytest.py
@@ -95,25 +95,9 @@ you can filter the function with a simpl
 
 from __future__ import print_function
 
-__docformat__ = "restructuredtext en"
-
-PYTEST_DOC = """%prog [OPTIONS] [testfile [testpattern]]
-
-examples:
-
-logilab-pytest path/to/mytests.py
-logilab-pytest path/to/mytests.py TheseTests
-logilab-pytest path/to/mytests.py TheseTests.test_thisone
-logilab-pytest path/to/mytests.py -m '(not long and database) or regr'
-
-logilab-pytest one (will run both test_thisone and test_thatone)
-logilab-pytest path/to/mytests.py -s not (will skip test_notthisone)
-"""
-
-ENABLE_DBC = False
-FILE_RESTART = ".pytest.restart"
-
-import os, sys, re
+import os
+import re
+import sys
 import os.path as osp
 from time import process_time, time
 from re import Match
@@ -130,7 +114,7 @@ from itertools import dropwhile
 from unittest.runner import _WritelnDecorator  # type: ignore
 from unittest.suite import TestSuite
 
-from typing import Callable, Any, Optional, List, Tuple, Generator, Union, Dict
+from typing import Callable, Any, Optional, List, Tuple, Generator, Dict
 
 from logilab.common.deprecation import deprecated
 from logilab.common.fileutils import abspath_listdir
@@ -139,12 +123,36 @@ from logilab.common import testlib, STD_
 
 # use the same unittest module as testlib
 from logilab.common.testlib import unittest, start_interactive_mode
-from logilab.common.testlib import nocoverage, pause_trace, replace_trace  # bwcompat
+from logilab.common.testlib import (  # noqa
+    nocoverage,
+    pause_trace,
+    replace_trace,
+)  # bwcompat
 from logilab.common.debugger import Debugger, colorize_source
 import doctest
 
 import unittest as unittest_legacy
 
+from .decorators import monkeypatch
+
+__docformat__ = "restructuredtext en"
+
+PYTEST_DOC = """%prog [OPTIONS] [testfile [testpattern]]
+
+examples:
+
+logilab-pytest path/to/mytests.py
+logilab-pytest path/to/mytests.py TheseTests
+logilab-pytest path/to/mytests.py TheseTests.test_thisone
+logilab-pytest path/to/mytests.py -m '(not long and database) or regr'
+
+logilab-pytest one (will run both test_thisone and test_thatone)
+logilab-pytest path/to/mytests.py -s not (will skip test_notthisone)
+"""
+
+ENABLE_DBC = False
+FILE_RESTART = ".pytest.restart"
+
 if not getattr(unittest_legacy, "__package__", None):
     try:
         import unittest2.suite as unittest_suite
@@ -155,7 +163,7 @@ else:
     import unittest.suite as unittest_suite  # type: ignore
 
 try:
-    import django
+    import django  # noqa
     from logilab.common.modutils import modpath_from_file, load_module_from_modpath
 
     DJANGO_FOUND = True
@@ -164,7 +172,7 @@ except ImportError:
 
 CONF_FILE = "pytestconf.py"
 
-TESTFILE_RE = re.compile("^((unit)?test.*|smoketest)\.py$")
+TESTFILE_RE = re.compile(r"^((unit)?test.*|smoketest)\.py$")
 
 
 def this_is_a_testfile(filename: str) -> Optional[Match]:
@@ -442,14 +450,12 @@ class DjangoTester(PyTester):
     def load_django_settings(self, dirname):
         """try to find project's setting and load it"""
         curdir = osp.abspath(dirname)
-        previousdir = curdir
         while not osp.isfile(osp.join(curdir, "settings.py")) and osp.isfile(
             osp.join(curdir, "__init__.py")
         ):
             newdir = osp.normpath(osp.join(curdir, os.pardir))
             if newdir == curdir:
                 raise AssertionError("could not find settings.py")
-            previousdir = curdir
             curdir = newdir
         # late django initialization
         settings = load_module_from_modpath(modpath_from_file(osp.join(curdir, "settings.py")))
@@ -704,7 +710,7 @@ def run():
     # mock a new command line
     sys.argv[1:] = parser.newargs
     cvg = None
-    if not "" in sys.path:
+    if "" not in sys.path:
         sys.path.insert(0, "")
     if DJANGO_FOUND and options.django:
         tester = DjangoTester(cvg, options)
@@ -729,7 +735,7 @@ def run():
                 cmd(*args)
         except SystemExit:
             raise
-        except:
+        except Exception:
             import traceback
 
             traceback.print_exc()
@@ -1068,9 +1074,13 @@ class SkipAwareTestResult(unittest._Text
 
     def _iter_valid_frames(self, frames: List[FrameInfo]) -> Generator[FrameInfo, Any, None]:
         """only consider non-testlib frames when formatting  traceback"""
+
+        def invalid(fi):
+            return osp.abspath(fi[1]) in (lgc_testlib, std_testlib)
+
         lgc_testlib = osp.abspath(__file__)
         std_testlib = osp.abspath(unittest.__file__)
-        invalid = lambda fi: osp.abspath(fi[1]) in (lgc_testlib, std_testlib)
+
         for frameinfo in dropwhile(invalid, frames):
             yield frameinfo
 
@@ -1115,7 +1125,7 @@ class SkipAwareTestResult(unittest._Text
         """err ->  (exc_type, exc, tcbk)"""
         exc_type, exc, _ = err
         if isinstance(exc, testlib.SkipTest):
-            assert exc_type == SkipTest
+            assert exc_type == testlib.SkipTest
             self.addSkip(test, exc)
         else:
             if self.exitfirst:
@@ -1160,8 +1170,6 @@ class SkipAwareTestResult(unittest._Text
             self.stream.writeln("no stderr".center(len(self.separator2)))
 
 
-from .decorators import monkeypatch
-
 orig_call = testlib.TestCase.__call__
 
 
@@ -1387,7 +1395,7 @@ if sys.version_info >= (2, 7):
     # The function below implements a modified version of the
     # TestSuite.run method that is provided with python 2.7, in
     # unittest/suite.py
-    def _ts_run(
+    def _ts_run(  # noqa
         self: Any,
         result: SkipAwareTestResult,
         debug: bool = False,
diff --git a/logilab/common/registry.py b/logilab/common/registry.py
--- a/logilab/common/registry.py
+++ b/logilab/common/registry.py
@@ -94,8 +94,6 @@ from warnings import warn
 from typing import List, Tuple, Any, Iterable, Callable
 from types import ModuleType
 from typing_extensions import TypedDict
-from _frozen_importlib import ModuleSpec
-from _frozen_importlib_external import SourceFileLoader
 
 from logilab.common.modutils import modpath_from_file
 from logilab.common.logging_ext import set_log_methods
@@ -134,7 +132,7 @@ def objectify_predicate(selector_func: C
 
 def wrap_predicates(decorator: Callable) -> None:
     for predicate in _PREDICATES.values():
-        if not "_decorators" in predicate.__dict__:
+        if "_decorators" not in predicate.__dict__:
             predicate._decorators = set()
         if decorator in predicate._decorators:
             continue
@@ -568,7 +566,7 @@ class Registry(dict):
 
     def register(self, obj: Any, oid: Optional[Any] = None, clear: bool = False) -> None:
         """base method to add an object in the registry"""
-        assert not "__abstract__" in obj.__dict__, obj
+        assert "__abstract__" not in obj.__dict__, obj
         assert obj.__select__, obj
         oid = oid or obj.__regid__
         assert oid, (
@@ -578,7 +576,7 @@ class Registry(dict):
             objects = self[oid] = []
         else:
             objects = self.setdefault(oid, [])
-        assert not obj in objects, "object %s is already registered" % obj
+        assert obj not in objects, "object %s is already registered" % obj
         objects.append(obj)
 
     def register_and_replace(self, obj, replaced):
@@ -943,7 +941,7 @@ class RegistryStore(dict):
             "modname expected to be a module name (ie string), got %r" % modname
         )
         for obj in objects:
-            if self.is_registrable(obj) and obj.__module__ == modname and not obj in butclasses:
+            if self.is_registrable(obj) and obj.__module__ == modname and obj not in butclasses:
                 if isinstance(obj, type):
                     self._load_ancestors_then_object(modname, obj, butclasses)
                 else:
diff --git a/logilab/common/shellutils.py b/logilab/common/shellutils.py
--- a/logilab/common/shellutils.py
+++ b/logilab/common/shellutils.py
@@ -26,12 +26,9 @@ from __future__ import print_function
 import os
 import glob
 import shutil
-import stat
 import sys
 import tempfile
-import time
 import fnmatch
-import errno
 import string
 import random
 import subprocess
@@ -41,7 +38,6 @@ from _io import StringIO
 from typing import Any, Callable, Optional, List, Union, Iterator, Tuple
 
 from logilab.common import STD_BLACKLIST, _handle_blacklist
-from logilab.common.compat import str_to_bytes
 from logilab.common.deprecation import deprecated
 
 
diff --git a/logilab/common/sphinx_ext.py b/logilab/common/sphinx_ext.py
--- a/logilab/common/sphinx_ext.py
+++ b/logilab/common/sphinx_ext.py
@@ -18,6 +18,14 @@
 from logilab.common.decorators import monkeypatch
 
 from sphinx.ext import autodoc
+from sphinx.ext.autodoc import (
+    ViewList,
+    Options,
+    AutodocReporter,
+    nodes,
+    assemble_option_dict,
+    nested_parse_with_titles,
+)
 
 
 class DocstringOnlyModuleDocumenter(autodoc.ModuleDocumenter):
@@ -45,16 +53,6 @@ def setup(app):
     app.add_autodocumenter(DocstringOnlyModuleDocumenter)
 
 
-from sphinx.ext.autodoc import (
-    ViewList,
-    Options,
-    AutodocReporter,
-    nodes,
-    assemble_option_dict,
-    nested_parse_with_titles,
-)
-
-
 @monkeypatch(autodoc.AutoDirective)
 def run(self):
     self.filename_set = set()  # a set of dependent filenames
diff --git a/logilab/common/sphinxutils.py b/logilab/common/sphinxutils.py
--- a/logilab/common/sphinxutils.py
+++ b/logilab/common/sphinxutils.py
@@ -29,7 +29,7 @@ Typical usage:
 >>> mgen.generate('api_logilab_common.rst', exclude_dirs=('test',))
 """
 
-import os, sys
+import sys
 import os.path as osp
 import inspect
 
@@ -113,7 +113,7 @@ class ModuleGenerator:
                 continue
             try:
                 module = load_module_from_file(filepath)
-            except:  # module might be broken or magic
+            except Exception:  # module might be broken or magic
                 dotted_path = modpath_from_file(filepath)
                 module = type(".".join(dotted_path), (), {})  # mock it
             yield module
diff --git a/logilab/common/table.py b/logilab/common/table.py
--- a/logilab/common/table.py
+++ b/logilab/common/table.py
@@ -21,7 +21,8 @@ from __future__ import print_function
 from types import CodeType
 from typing import Any, List, Optional, Tuple, Union, Dict, Iterator
 from _io import StringIO
-from mypy_extensions import NoReturn
+
+import re
 
 __docformat__ = "restructuredtext en"
 
@@ -82,7 +83,7 @@ class Table(object):
     def __len__(self) -> int:
         return len(self.row_names)
 
-    ## Rows / Columns creation #################################################
+    # Rows / Columns creation #################################################
     def create_rows(self, row_names: List[str]) -> None:
         """Appends row_names to the list of existing rows
         """
@@ -110,7 +111,7 @@ class Table(object):
         for row in self.data:
             row.append(self.default_value)
 
-    ## Sort by column ##########################################################
+    # Sort by column ##########################################################
     def sort_by_column_id(self, col_id: str, method: str = "asc") -> None:
         """Sorts the table (in-place) according to data stored in col_id
         """
@@ -176,7 +177,7 @@ class Table(object):
             if row[col_index] == value:
                 self.data.remove(row)
 
-    ## The 'setter' part #######################################################
+    # The 'setter' part #######################################################
     def set_cell(self, row_index: int, col_index: int, data: int) -> None:
         """sets value of cell 'row_indew', 'col_index' to data
         """
@@ -332,7 +333,7 @@ class Table(object):
         except ValueError:
             raise KeyError("Column (%s) not found in table" % (col_id))
 
-    ## The 'getter' part #######################################################
+    # The 'getter' part #######################################################
 
     def get_shape(self) -> Tuple[int, int]:
         """Returns a tuple which represents the table's shape
@@ -649,8 +650,6 @@ class TableStyle:
         return self.units[col_id]
 
 
-import re
-
 CELL_PROG = re.compile("([0-9]+)_([0-9]+)")
 
 
diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py
--- a/logilab/common/testlib.py
+++ b/logilab/common/testlib.py
@@ -46,25 +46,26 @@ from __future__ import print_function
 
 from contextlib import contextmanager
 import sys
-import os, os.path as osp
-import re
-import difflib
+import os
+import os.path as osp
 import tempfile
-import math
 import warnings
 from shutil import rmtree
-from operator import itemgetter
 from inspect import isgeneratorfunction
 from typing import Any, Iterator, Union, Optional, Callable, Dict, List, Tuple
 from mypy_extensions import NoReturn
 
 import builtins
-import configparser
+import doctest
 
 from logilab.common.deprecation import class_deprecated, deprecated
 
 import unittest as unittest_legacy
 
+from functools import wraps
+
+from logilab.common.decorators import cached, classproperty
+
 if not getattr(unittest_legacy, "__package__", None):
     try:
         import unittest2 as unittest
@@ -77,12 +78,6 @@ else:
     import unittest as unittest  # type: ignore
     from unittest import SkipTest
 
-from functools import wraps
-
-from logilab.common.debugger import Debugger
-from logilab.common.decorators import cached, classproperty
-from logilab.common import textutils
-
 
 __all__ = ["unittest_main", "find_tests", "nocoverage", "pause_trace"]
 
@@ -176,7 +171,7 @@ def find_tests(testdir, prefixes=DEFAULT
     return tests
 
 
-## PostMortem Debug facilities #####
+# PostMortem Debug facilities #####
 def start_interactive_mode(result):
     """starts an interactive shell so that the user can inspect errors
     """
@@ -283,8 +278,6 @@ unittest_main = unittest.main
 class InnerTestSkipped(SkipTest):
     """raised when a test is skipped"""
 
-    pass
-
 
 def parse_generative_args(params: Tuple[int, ...]) -> Tuple[Union[List[bool], List[int]], Dict]:
     args = []
@@ -416,7 +409,7 @@ class TestCase(unittest.TestCase):
                 )
                 result.addSuccess(self)
             return False
-        except:
+        except Exception:
             result.addError(self, self.__exc_info())
             return False
         return True
@@ -513,7 +506,7 @@ class TestCase(unittest.TestCase):
             success = False
         except SkipTest as e:
             result.addSkip(self, e)
-        except:
+        except Exception:
             # if an error occurs between two yield
             result.addError(self, self.__exc_info())
             success = False
@@ -547,7 +540,7 @@ class TestCase(unittest.TestCase):
         except SkipTest as e:
             result.addSkip(self, e)
             return 0
-        except:
+        except Exception:
             result.addError(self, self.__exc_info())
             return 2
         return 0
@@ -567,8 +560,6 @@ TestCase.assertItemsEqual = deprecated("
     TestCase.assertItemsEqual
 )
 
-import doctest
-
 
 class SkippedSuite(unittest.TestSuite):
     def test(self):
@@ -658,12 +649,11 @@ class MockConnection:
 
     def close(self):
         """Mock close method"""
-        pass
 
 
 # mypy error: Name 'Mock' is not defined
 # dynamic class created by this class
-def mock_object(**params: Any) -> "Mock":  # type: ignore
+def mock_object(**params: Any) -> "Mock":  # type: ignore # noqa
     """creates an object using params to set attributes
     >>> option = mock_object(verbose=False, index=range(5))
     >>> option.verbose
diff --git a/logilab/common/textutils.py b/logilab/common/textutils.py
--- a/logilab/common/textutils.py
+++ b/logilab/common/textutils.py
@@ -136,7 +136,7 @@ def unquote(string: str) -> str:
 
 
 _BLANKLINES_RGX = re.compile("\r?\n\r?\n")
-_NORM_SPACES_RGX = re.compile("\s+")
+_NORM_SPACES_RGX = re.compile(r"\s+")
 
 
 def normalize_text(text: str, line_len: int = 80, indent: str = "", rest: bool = False) -> str:
diff --git a/logilab/common/tree.py b/logilab/common/tree.py
--- a/logilab/common/tree.py
+++ b/logilab/common/tree.py
@@ -25,12 +25,10 @@
 
 import sys
 
-# from logilab.common import flatten
 from logilab.common.visitor import VisitedMixIn, FilteredIterator, no_filter
-from logilab.common.types import Paragraph, Title
-from typing import Optional, Any, Union, List, Callable, TypeVar
-
-## Exceptions #################################################################
+from typing import Optional, Any, List, Callable
+
+# Exceptions #################################################################
 
 
 class NodeNotFound(Exception):
@@ -244,7 +242,6 @@ class VNode(Node, VisitedMixIn):
     # we should probably merge this VisitedMixIn here because it's only used here
     """a visitable node
     """
-    pass
 
 
 class BinaryNode(VNode):
diff --git a/logilab/common/umessage.py b/logilab/common/umessage.py
--- a/logilab/common/umessage.py
+++ b/logilab/common/umessage.py
@@ -113,7 +113,8 @@ class UMessage:
         message = self.message
 
         if index is None:
-            # mypy: Argument 1 to "get_payload" of "Message" has incompatible type "None"; expected "int"
+            # mypy: Argument 1 to "get_payload" of "Message" has incompatible type "None";
+            # mypy: expected "int"
             # email.message.Message.get_payload has type signature:
             # Message.get_payload(self, i=None, decode=False)
             # so None seems to be totally acceptable, I don't understand mypy here
diff --git a/logilab/common/ureports/__init__.py b/logilab/common/ureports/__init__.py
--- a/logilab/common/ureports/__init__.py
+++ b/logilab/common/ureports/__init__.py
@@ -24,11 +24,12 @@ formatted as text and html.
 
 import sys
 
+from typing import Any, Optional, Union, List, Generator, Tuple, Callable, TextIO
+
 from logilab.common.compat import StringIO
 from logilab.common.textutils import linesep
 from logilab.common.tree import VNode
-from logilab.common.ureports.nodes import Table, List as NodeList
-from typing import Any, Optional, Union, List, Generator, Tuple, Callable, TextIO
+from logilab.common.ureports.nodes import Table, Section, Link, Paragraph, Title, Text
 
 
 def get_nodes(node, klass):
@@ -208,10 +209,5 @@ class BaseWriter(object):
             del self.writeln
 
 
-# mypy error: Incompatible import of "Table" (imported name has type
-# mypy error: "Type[logilab.common.ureports.nodes.Table]", local name has type
-# mypy error: "Type[logilab.common.table.Table]")
-# this will be cleaned when the "*" will be removed
-from logilab.common.ureports.nodes import *  # type: ignore
-from logilab.common.ureports.text_writer import TextWriter
-from logilab.common.ureports.html_writer import HTMLWriter
+from logilab.common.ureports.text_writer import TextWriter  # noqa
+from logilab.common.ureports.html_writer import HTMLWriter  # noqa
diff --git a/logilab/common/ureports/docbook_writer.py b/logilab/common/ureports/docbook_writer.py
--- a/logilab/common/ureports/docbook_writer.py
+++ b/logilab/common/ureports/docbook_writer.py
@@ -18,7 +18,7 @@
 """HTML formatting drivers for ureports"""
 __docformat__ = "restructuredtext en"
 
-from logilab.common.ureports import HTMLWriter
+from logilab.common.ureports.html_writer import HTMLWriter
 
 
 class DocbookWriter(HTMLWriter):
diff --git a/logilab/common/urllib2ext.py b/logilab/common/urllib2ext.py
--- a/logilab/common/urllib2ext.py
+++ b/logilab/common/urllib2ext.py
@@ -6,15 +6,15 @@ import urllib2
 import kerberos as krb
 
 
+import re
+
+RGX = re.compile(r"(?:.*,)*\s*Negotiate\s*([^,]*),?", re.I)
+
+
 class GssapiAuthError(Exception):
     """raised on error during authentication process"""
 
 
-import re
-
-RGX = re.compile("(?:.*,)*\s*Negotiate\s*([^,]*),?", re.I)
-
-
 def get_negociate_value(headers):
     for authreq in headers.getheaders("www-authenticate"):
         match = RGX.search(authreq)
@@ -85,8 +85,6 @@ if __name__ == "__main__":
 
     httplib.HTTPConnection.debuglevel = 1
     httplib.HTTPSConnection.debuglevel = 1
-    # debug
-    import logging
 
     logging.basicConfig(level=logging.DEBUG)
     # handle cookies
diff --git a/logilab/common/vcgutils.py b/logilab/common/vcgutils.py
--- a/logilab/common/vcgutils.py
+++ b/logilab/common/vcgutils.py
@@ -177,7 +177,7 @@ def latin_to_vcg(st):
                 num = ord(char)
                 if num >= 192:
                     st = st.replace(char, r"\fi%d" % ord(char))
-            except:
+            except Exception:
                 pass
     return st
 
diff --git a/logilab/common/visitor.py b/logilab/common/visitor.py
--- a/logilab/common/visitor.py
+++ b/logilab/common/visitor.py
@@ -42,7 +42,7 @@ class FilteredIterator(object):
     def __next__(self) -> Optional[Node]:
         try:
             return self._list.pop(0)
-        except:
+        except Exception:
             return None
 
     next = __next__
@@ -80,7 +80,6 @@ class Visitor(object):
         """
         method called at the beginning of the visit
         """
-        pass
 
     def close_visit(self, result):
         """
@@ -105,7 +104,7 @@ class VisitedMixIn(object):
             # mypy: "VisitedMixIn" has no attribute "TYPE"
             # dynamic attribute
             return self.TYPE.replace("-", "_")  # type: ignore
-        except:
+        except Exception:
             return self.__class__.__name__.lower()
 
     def accept(
diff --git a/logilab/common/xmlutils.py b/logilab/common/xmlutils.py
--- a/logilab/common/xmlutils.py
+++ b/logilab/common/xmlutils.py
@@ -29,10 +29,10 @@ instruction and return a Python dictiona
 __docformat__ = "restructuredtext en"
 
 import re
-from typing import Dict, Optional, Union
+from typing import Dict, Optional
 
-RE_DOUBLE_QUOTE = re.compile('([\w\-\.]+)="([^"]+)"')
-RE_SIMPLE_QUOTE = re.compile("([\w\-\.]+)='([^']+)'")
+RE_DOUBLE_QUOTE = re.compile(r'([\w\-\.]+)="([^"]+)"')
+RE_SIMPLE_QUOTE = re.compile(r"([\w\-\.]+)='([^']+)'")
 
 
 def parse_pi_data(pi_data: str) -> Dict[str, Optional[str]]:
diff --git a/test/data/module.py b/test/data/module.py
--- a/test/data/module.py
+++ b/test/data/module.py
@@ -5,7 +5,6 @@ from __future__ import print_function
 
 from logilab.common import modutils, Execute as spawn
 from logilab.common.astutils import *
-import os.path
 
 MY_DICT = {}
 
diff --git a/test/data/noendingnewline.py b/test/data/noendingnewline.py
--- a/test/data/noendingnewline.py
+++ b/test/data/noendingnewline.py
@@ -16,15 +16,12 @@ class TestCase(unittest.TestCase):
 
     def xxx(self):
         if False:
-            pass
             print("a")
 
         if False:
             pass
-            pass
 
         if False:
-            pass
             print("rara")
 
 
diff --git a/test/test_cache.py b/test/test_cache.py
--- a/test/test_cache.py
+++ b/test/test_cache.py
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU Lesser General Public License along
 # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
 
-from logilab.common.testlib import TestCase, unittest_main, TestSuite
+from logilab.common.testlib import TestCase, unittest_main
 from logilab.common.cache import Cache
 
 
diff --git a/test/test_configuration.py b/test/test_configuration.py
--- a/test/test_configuration.py
+++ b/test/test_configuration.py
@@ -141,7 +141,7 @@ class ConfigurationTC(TestCase):
 
     def test_load_configuration(self):
         cfg = self.cfg
-        args = cfg.load_configuration(
+        cfg.load_configuration(
             choice="ye", number="4", multiple="1,2,3", dothis="n", multiple_choice=("yo", "ya")
         )
         self.assertEqual(cfg["dothis"], False)
diff --git a/test/test_date.py b/test/test_date.py
--- a/test/test_date.py
+++ b/test/test_date.py
@@ -42,7 +42,6 @@ try:
         DateTime as mxDateTime,
         now as mxNow,
         RelativeDateTime,
-        RelativeDate,
     )
 except ImportError:
     mxDate = mxDateTime = RelativeDateTime = mxNow = None
diff --git a/test/test_fileutils.py b/test/test_fileutils.py
--- a/test/test_fileutils.py
+++ b/test/test_fileutils.py
@@ -19,13 +19,24 @@
 
 import doctest
 import io
-import sys, os, tempfile, shutil
+import sys
+import os
+import tempfile
+import shutil
 from stat import S_IWRITE
 from os.path import join
 
-from logilab.common.testlib import TestCase, unittest_main, unittest
+from logilab.common.testlib import TestCase, unittest_main
 
-from logilab.common.fileutils import *
+from logilab.common.fileutils import (
+    first_level_directory,
+    is_binary,
+    write_open_mode,
+    lines,
+    export,
+    exists,
+    ProtectedFile,
+)
 
 DATA_DIR = join(os.path.abspath(os.path.dirname(__file__)), "data")
 NEWLINES_TXT = join(DATA_DIR, "newlines.txt")
@@ -100,13 +111,14 @@ class ProtectedFileTC(TestCase):
         # test on non-writable file
         # self.assertTrue(not os.access(self.rpath, os.W_OK))
         self.assertTrue(not os.stat(self.rpath).st_mode & S_IWRITE)
-        wp_file = ProtectedFile(self.rpath, "w")
+        # for some reason if you remove "wp_file =" the test fails
+        wp_file = ProtectedFile(self.rpath, "w")  # noqa
         self.assertTrue(os.stat(self.rpath).st_mode & S_IWRITE)
         self.assertTrue(os.access(self.rpath, os.W_OK))
         # test on writable-file
         self.assertTrue(os.stat(self.rwpath).st_mode & S_IWRITE)
         self.assertTrue(os.access(self.rwpath, os.W_OK))
-        wp_file = ProtectedFile(self.rwpath, "w")
+        ProtectedFile(self.rwpath, "w")
         self.assertTrue(os.stat(self.rwpath).st_mode & S_IWRITE)
         self.assertTrue(os.access(self.rwpath, os.W_OK))
 
diff --git a/test/test_interface.py b/test/test_interface.py
--- a/test/test_interface.py
+++ b/test/test_interface.py
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU Lesser General Public License along
 # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
 from logilab.common.testlib import TestCase, unittest_main
-from logilab.common.interface import *
+from logilab.common.interface import Interface, extend
 
 
 class IFace1(Interface):
diff --git a/test/test_modutils.py b/test/test_modutils.py
--- a/test/test_modutils.py
+++ b/test/test_modutils.py
@@ -151,8 +151,8 @@ class modpath_from_file_tc(ModutilsTestC
 class load_module_from_path_tc(ModutilsTestCase):
     def test_do_not_load_twice(self):
         sys.path.insert(0, self.datadir)
-        foo = modutils.load_module_from_modpath(["lmfp", "foo"])
-        lmfp = modutils.load_module_from_modpath(["lmfp"])
+        modutils.load_module_from_modpath(["lmfp", "foo"])
+        modutils.load_module_from_modpath(["lmfp"])
         self.assertEqual(len(sys.just_once), 1)
         sys.path.pop(0)
         del sys.just_once
@@ -272,7 +272,7 @@ class is_relative_tc(ModutilsTestCase):
 
 
 class get_modules_tc(ModutilsTestCase):
-    def test_knownValues_get_modules_1(self):  #  XXXFIXME: TOWRITE
+    def test_knownValues_get_modules_1(self):  # XXXFIXME: TOWRITE
         """given a directory return a list of all available python modules, even
         in subdirectories
         """
@@ -292,7 +292,7 @@ class get_modules_tc(ModutilsTestCase):
 
 
 class get_modules_files_tc(ModutilsTestCase):
-    def test_knownValues_get_module_files_1(self):  #  XXXFIXME: TOWRITE
+    def test_knownValues_get_module_files_1(self):  # XXXFIXME: TOWRITE
         """given a directory return a list of all available python module's files, even
         in subdirectories
         """
diff --git a/test/test_pytest.py b/test/test_pytest.py
--- a/test/test_pytest.py
+++ b/test/test_pytest.py
@@ -15,9 +15,17 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
+import sys
+
 from os.path import join
 from logilab.common.testlib import TestCase, unittest_main
-from logilab.common.pytest import *
+from logilab.common.pytest import (
+    this_is_a_testdir,
+    this_is_a_testfile,
+    replace_trace,
+    pause_trace,
+    nocoverage,
+)
 
 
 class ModuleFunctionTC(TestCase):
diff --git a/test/test_registry.py b/test/test_registry.py
--- a/test/test_registry.py
+++ b/test/test_registry.py
@@ -19,18 +19,26 @@
 
 import gc
 import logging
-import os.path as osp
 import sys
-from operator import eq, lt, le, gt
 from contextlib import contextmanager
 import warnings
 
+from logilab.common.testlib import (
+    TestCase,
+    unittest_main,
+)
+
+from logilab.common.registry import (
+    Predicate,
+    AndPredicate,
+    OrPredicate,
+    wrap_predicates,
+    RegistryStore,
+    RegistrableInstance,
+)
+
 logging.basicConfig(level=logging.ERROR)
 
-from logilab.common.testlib import TestCase, unittest_main
-
-from logilab.common.registry import *
-
 
 class _1_(Predicate):
     def __call__(self, *args, **kwargs):
diff --git a/test/test_shellutils.py b/test/test_shellutils.py
--- a/test/test_shellutils.py
+++ b/test/test_shellutils.py
@@ -17,9 +17,7 @@
 # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
 """unit tests for logilab.common.shellutils"""
 
-import sys, os, tempfile, shutil
 from os.path import join, dirname, abspath
-import datetime, time
 from unittest.mock import patch
 
 from logilab.common.testlib import TestCase, unittest_main
@@ -197,7 +195,6 @@ class ProgressBarTC(TestCase):
         expected_stream = StringIO()
         size = 20
         pgb = ProgressBar(100, size, stream=pgb_stream)
-        last = 0
         for dots in range(10, 105, 15):
             pgb.update(dots, exact=True)
             dots //= 5
@@ -209,7 +206,6 @@ class ProgressBarTC(TestCase):
         expected_stream = StringIO()
         size = 20
         pgb = ProgressBar(100, size, stream=pgb_stream)
-        last = 0
         for dots in range(5, 105, 5):
             pgb.update(5, exact=False)
             dots //= 5
@@ -259,13 +255,13 @@ class RawInputTC(TestCase):
 
     def test_ask_prompt(self):
         self.input_answer = ""
-        answer = self.qa.ask("text", ("yes", "no"), "yes")
+        self.qa.ask("text", ("yes", "no"), "yes")
         self.assertEqual(self.input_args[0], "text [Y(es)/n(o)]: ")
-        answer = self.qa.ask("text", ("y", "n"), "y")
+        self.qa.ask("text", ("y", "n"), "y")
         self.assertEqual(self.input_args[0], "text [Y/n]: ")
-        answer = self.qa.ask("text", ("n", "y"), "y")
+        self.qa.ask("text", ("n", "y"), "y")
         self.assertEqual(self.input_args[0], "text [n/Y]: ")
-        answer = self.qa.ask("text", ("yes", "no", "maybe", "1"), "yes")
+        self.qa.ask("text", ("yes", "no", "maybe", "1"), "yes")
         self.assertEqual(self.input_args[0], "text [Y(es)/n(o)/m(aybe)/1]: ")
 
     def test_ask_ambiguous(self):
diff --git a/test/test_table.py b/test/test_table.py
--- a/test/test_table.py
+++ b/test/test_table.py
@@ -21,7 +21,6 @@ Unittests for table management
 
 
 import sys
-import os
 
 from logilab.common.compat import StringIO
 from logilab.common.testlib import TestCase, unittest_main
@@ -379,7 +378,7 @@ class TableStyleTC(TestCase):
         """tests style's get and set by index methods"""
         for attrname, default_value in self._tested_attrs:
             getter = getattr(self.style, "get_%s" % attrname)
-            setter = getattr(self.style, "set_%s" % attrname)
+            getattr(self.style, "set_%s" % attrname)
             igetter = getattr(self.style, "get_%s_by_index" % attrname)
             isetter = getattr(self.style, "set_%s_by_index" % attrname)
             self.assertEqual(getter("__row_column__"), default_value)
diff --git a/test/test_taskqueue.py b/test/test_taskqueue.py
--- a/test/test_taskqueue.py
+++ b/test/test_taskqueue.py
@@ -17,7 +17,7 @@
 # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
 from logilab.common.testlib import TestCase, unittest_main
 
-from logilab.common.tasksqueue import *
+from logilab.common.tasksqueue import Task, PrioritizedTasksQueue, LOW, MEDIUM, HIGH
 
 
 class TaskTC(TestCase):
diff --git a/test/test_testlib.py b/test/test_testlib.py
--- a/test/test_testlib.py
+++ b/test/test_testlib.py
@@ -32,7 +32,6 @@ except NameError:
 
 from logilab.common.compat import StringIO
 from logilab.common.testlib import (
-    unittest,
     TestSuite,
     unittest_main,
     Tags,
@@ -443,7 +442,7 @@ class ExitFirstTC(TestCase):
 
 
 class TestLoaderTC(TestCase):
-    ## internal classes for test purposes ########
+    # internal classes for test purposes ########
     class FooTC(TestCase):
         def test_foo1(self):
             pass
@@ -804,7 +803,6 @@ class DecoratorTC(TestCase):
         for module in modules:
             try:
                 __import__(module)
-                pass
             except ImportError:
                 decorator = require_module(module)
                 self.assertNotEqual(
diff --git a/test/test_textutils.py b/test/test_textutils.py
--- a/test/test_textutils.py
+++ b/test/test_textutils.py
@@ -21,6 +21,9 @@ unit tests for module textutils
 squeleton generated by /home/syt/cvs_work/logilab/pyreverse/py2tests.py on Sep 08 at 09:1:31
 
 """
+
+# flake8: noqa: E501
+
 import doctest
 import re
 from os import linesep
@@ -30,8 +33,6 @@ from logilab.common.testlib import TestC
 
 
 if linesep != "\n":
-    import re
-
     LINE_RGX = re.compile(linesep)
 
     def ulines(string):
diff --git a/test/test_tree.py b/test/test_tree.py
--- a/test/test_tree.py
+++ b/test/test_tree.py
@@ -21,7 +21,14 @@ squeleton generated by /home/syt/bin/py2
 """
 
 from logilab.common.testlib import TestCase, unittest_main
-from logilab.common.tree import *
+from logilab.common.tree import (
+    Node,
+    NodeNotFound,
+    post_order_list,
+    PostfixedDepthFirstIterator,
+    pre_order_list,
+    PrefixedDepthFirstIterator,
+)
 
 tree = (
     "root",
@@ -196,9 +203,17 @@ class post_order_list_FunctionTest(TestC
         create a list with tree nodes for which the <filter> function returned true
         in a post order foashion
         """
-        L = ["child_2_1", "child_3_1", "child_2_2", "child_1_1", "child_2_3", "child_1_2", "root"]
-        l = [n.id for n in post_order_list(self.o)]
-        self.assertEqual(l, L, l)
+        L = [
+            "child_2_1",
+            "child_3_1",
+            "child_2_2",
+            "child_1_1",
+            "child_2_3",
+            "child_1_2",
+            "root",
+        ]
+        li = [n.id for n in post_order_list(self.o)]
+        self.assertEqual(li, L, li)
 
     def test_known_values_post_order_list2(self):
         """
@@ -212,8 +227,8 @@ class post_order_list_FunctionTest(TestC
             return 1
 
         L = ["child_2_1", "child_1_1", "child_2_3", "child_1_2", "root"]
-        l = [n.id for n in post_order_list(self.o, filter)]
-        self.assertEqual(l, L, l)
+        li = [n.id for n in post_order_list(self.o, filter)]
+        self.assertEqual(li, L, li)
 
 
 class PostfixedDepthFirstIterator_ClassTest(TestCase):
@@ -246,9 +261,17 @@ class pre_order_list_FunctionTest(TestCa
         create a list with tree nodes for which the <filter> function returned true
         in a pre order fashion
         """
-        L = ["root", "child_1_1", "child_2_1", "child_2_2", "child_3_1", "child_1_2", "child_2_3"]
-        l = [n.id for n in pre_order_list(self.o)]
-        self.assertEqual(l, L, l)
+        L = [
+            "root",
+            "child_1_1",
+            "child_2_1",
+            "child_2_2",
+            "child_3_1",
+            "child_1_2",
+            "child_2_3",
+        ]
+        li = [n.id for n in pre_order_list(self.o)]
+        self.assertEqual(li, L, li)
 
     def test_known_values_pre_order_list2(self):
         """
@@ -262,8 +285,8 @@ class pre_order_list_FunctionTest(TestCa
             return 1
 
         L = ["root", "child_1_1", "child_2_1", "child_1_2", "child_2_3"]
-        l = [n.id for n in pre_order_list(self.o, filter)]
-        self.assertEqual(l, L, l)
+        li = [n.id for n in pre_order_list(self.o, filter)]
+        self.assertEqual(li, L, li)
 
 
 class PrefixedDepthFirstIterator_ClassTest(TestCase):
diff --git a/test/test_ureports_html.py b/test/test_ureports_html.py
--- a/test/test_ureports_html.py
+++ b/test/test_ureports_html.py
@@ -18,10 +18,11 @@
 """unit tests for ureports.html_writer
 """
 
+# flake8: noqa: E501
 
 from utils import WriterTC
 from logilab.common.testlib import TestCase, unittest_main
-from logilab.common.ureports.html_writer import *
+from logilab.common.ureports.html_writer import HTMLWriter
 
 
 class HTMLWriterTC(TestCase, WriterTC):
diff --git a/test/utils.py b/test/utils.py
--- a/test/utils.py
+++ b/test/utils.py
@@ -23,6 +23,16 @@ from __future__ import print_function
 import sys
 from io import StringIO
 
+from logilab.common.ureports.nodes import (
+    Section,
+    Text,
+    Table,
+    VerbatimText,
+    List,
+    Paragraph,
+    Link,
+)
+
 buffers = [StringIO]
 if sys.version_info < (3, 0):
     from cStringIO import StringIO as cStringIO
@@ -30,8 +40,6 @@ if sys.version_info < (3, 0):
 
     buffers += [cStringIO, pStringIO]
 
-from logilab.common.ureports.nodes import *
-
 
 class WriterTC:
     def _test_output(self, test_id, layout, msg=None):
@@ -42,7 +50,7 @@ class WriterTC:
             expected = getattr(self, test_id)
             try:
                 self.assertMultiLineEqual(got, expected)
-            except:
+            except Exception:
                 print("**** using a %s" % buffer.__class__)
                 print("**** got for %s" % test_id)
                 print(got)
@@ -90,8 +98,3 @@ class WriterTC:
         table.append(Link("http://www.perdu.com", "toi perdu ?"))
         table.append(Text(""))
         self._test_output("advanced_table", table)
-
-
-##     def test_image(self):
-##         layout = Verbatim('blablabla')
-##         self._test_output('verbatim_base', layout)




More information about the cubicweb-devel mailing list