From: Guido van Rossum Date: Tue, 24 Mar 1998 04:58:04 +0000 (+0000) Subject: Report first line with inconsistent tab usage. X-Git-Tag: v1.5.1~320 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3db0e3713cd59d1c922002056f11ae5caf02805c;p=python Report first line with inconsistent tab usage. --- diff --git a/Tools/scripts/tabpolice.py b/Tools/scripts/tabpolice.py index 9236b711f4..e65eb01a0f 100755 --- a/Tools/scripts/tabpolice.py +++ b/Tools/scripts/tabpolice.py @@ -51,10 +51,10 @@ def check(file): print "%s: Token Error: %s" % (`file`, str(msg)) if verbose > 1: - print "checking", `file`, "with tabsize 4..." + print "checking", `file`, "with tabsize 1..." f.seek(0) alttokens = [] - tokenize.tabsize = 4 + tokenize.tabsize = 1 try: tokenize.tokenize(f.readline, alttokens.append) except tokenize.TokenError, msg: @@ -62,10 +62,30 @@ def check(file): f.close() if tokens != alttokens: + badline = 0 + n, altn = len(tokens), len(alttokens) + for i in range(max(n, altn)): + if i >= n: + x = None + else: + x = tokens[i] + if i >= altn: + y = None + else: + y = alttokens[i] + if x != y: + if x: + kind, token, start, end, line = x + else: + kind, token, start, end, line = y + badline = start[0] + break if verbose: - print "%s: *** Trouble in tab city! ***" % `file` + print "%s: *** Line %d: trouble in tab city! ***" % ( + `file`, badline) + print "offending line:", `line` else: - print file + print file, badline, `line` else: if verbose: print "%s: Clean bill of health." % `file`