From c22f94069c5357052cd0315088bc9966271b27cb Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Sun, 27 Mar 2016 22:34:12 -0400 Subject: Tweak the import rules checker. Fix the last few violations of the import rules. --- src/mailman/testing/flake8.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/mailman/testing/flake8.py') diff --git a/src/mailman/testing/flake8.py b/src/mailman/testing/flake8.py index df4e39c90..18193d1e1 100644 --- a/src/mailman/testing/flake8.py +++ b/src/mailman/testing/flake8.py @@ -81,7 +81,22 @@ class ImportOrder: if last_import.itype is ImportType.from_import: yield self._error(record, 'B401', 'Non-from import follows from-import') - if len(last_import.names[0]) > len(record.names[0]): + # Shorter imports should always precede longer import *except* + # when they are dotted imports and everything but the last + # path component are the same. In that case, they should be + # sorted alphabetically. + last_name = last_import.names[0] + this_name = record.names[0] + if '.' in last_name and '.' in this_name: + last_parts = last_name.split('.') + this_parts = this_name.split('.') + if (last_parts[:-1] == this_parts[:-1] and + last_parts[-1] > this_parts[-1]): + yield self._error( + record, 'B410', + 'Dotted non-from import not sorted ' + 'alphabetically') + elif len(last_name) > len(this_name): yield self._error( record, 'B403', 'Shorter non-from import follows longer') -- cgit v1.2.3-70-g09d2