diff options
author | Laura M?dioni <laura.medioni@logilab.fr> | 2015-11-24 14:38:30 +0100 |
---|---|---|
committer | Laura M?dioni <laura.medioni@logilab.fr> | 2015-11-24 14:38:30 +0100 |
commit | 2a8566b37e375a698fc966d58e1c9e7ff18c4b82 (patch) | |
tree | ac433abb82800e119b14211e7d538cd024d6c980 | |
parent | 047ab37ac5a6b429b46e4b2d9aef9ede2c9cd570 (diff) | |
download | pylint-2a8566b37e375a698fc966d58e1c9e7ff18c4b82.tar.gz |
Simplify a bit the algorithm checking for ungrouped imports
related to issue #692
-rw-r--r-- | pylint/checkers/imports.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 6480d27..367b541 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -337,18 +337,14 @@ given file (report RP0402 must not be disabled)'} # check imports are grouped by category (standard, 3rd party, local) std_imports, ext_imports, loc_imports = self._check_imports_order(node) # check imports are grouped by package within a given category - for imports in (std_imports, ext_imports, loc_imports): - packages = [] - for imp in imports: - if packages and packages[-1] == imp[1]: - continue - # check if an import from the same package has already been made - for package in packages: - if imp[1] == package: - self.add_message('ungrouped-imports', node=imp[0], - args=package) - break - packages.append(imp[1]) + met = set() + curr_package = None + for imp in std_imports + ext_imports + loc_imports: + package, _, _ = imp[1].partition('.') + if curr_package and curr_package != package and package in met: + self.add_message('ungrouped-imports', node=imp[0], args=package) + curr_package = package + met.add(package) self._imports_stack = [] self._first_non_import_node = None |