import-checker: do not enforce lexical sort accross stdlib/local boundary
Before this change, you could get in a start where the checker would either
complain about importing local module before stdlib one or complain about the
local one being wrongly lexically sorted with the stdlib one.
We detect the boundary and avoid complaining about lexical sort across it.
--- a/contrib/import-checker.py Wed Dec 14 09:53:56 2016 -0800
+++ b/contrib/import-checker.py Thu Dec 15 19:56:48 2016 +0100
@@ -391,6 +391,7 @@
seennonsymbollocal = False
# The last name to be imported (for sorting).
lastname = None
+ laststdlib = None
# Relative import levels encountered so far.
seenlevels = set()
@@ -412,16 +413,18 @@
name = node.names[0].name
asname = node.names[0].asname
+ stdlib = name in stdlib_modules
+
# Ignore sorting rules on imports inside blocks.
if node.col_offset == root_col_offset:
- if lastname and name < lastname:
+ if lastname and name < lastname and laststdlib == stdlib:
yield msg('imports not lexically sorted: %s < %s',
name, lastname)
- lastname = name
+ lastname = name
+ laststdlib = stdlib
# stdlib imports should be before local imports.
- stdlib = name in stdlib_modules
if stdlib and seenlocal and node.col_offset == root_col_offset:
yield msg('stdlib import "%s" follows local import: %s',
name, seenlocal)