diff options
author | Guido van Rossum <guido@python.org> | 2001-09-02 14:11:30 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-09-02 14:11:30 +0000 |
commit | 89d435108a5f7ee5333d4a7c7abbdf349c8cea55 (patch) | |
tree | 4f3892ee8ed86d882231ef5f7789cec0c5eabe82 /Tools/scripts/fixdiv.py | |
parent | f78ea392c18ea688636dfbffc8430ba22fa37686 (diff) | |
download | cpython-89d435108a5f7ee5333d4a7c7abbdf349c8cea55.tar.gz |
Implement what the docstring said: multiple slashes per line are
treated the same as single ones by default. Added -m option to issue
a warning for this case instead.
Diffstat (limited to 'Tools/scripts/fixdiv.py')
-rwxr-xr-x | Tools/scripts/fixdiv.py | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/Tools/scripts/fixdiv.py b/Tools/scripts/fixdiv.py index 382503a060..616622b819 100755 --- a/Tools/scripts/fixdiv.py +++ b/Tools/scripts/fixdiv.py @@ -62,6 +62,7 @@ There are several possible recommendations and observations: multi-line statement, it's not clear whether both were executed. In practice, they usually are, so the default action is make the same recommendation for all / operators, based on the above criteria. + The -m option issues warnings for these cases instead. Notes: @@ -99,9 +100,11 @@ import re import tokenize from pprint import pprint +multi_ok = 1 + def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "h") + opts, args = getopt.getopt(sys.argv[1:], "hm") except getopt.error, msg: usage(msg) return 2 @@ -109,6 +112,9 @@ def main(): if o == "-h": print __doc__ return + if o == "-m": + global multi_ok + multi_ok = 0 if not args: usage("at least one file argument is required") return 2 @@ -130,7 +136,7 @@ def main(): def usage(msg): sys.stderr.write("%s: %s\n" % (sys.argv[0], msg)) - sys.stderr.write("Usage: %s warnings\n" % sys.argv[0]) + sys.stderr.write("Usage: %s [-m] warnings\n" % sys.argv[0]) sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0]) PATTERN = ("^(.+?):(\d+): DeprecationWarning: " @@ -197,24 +203,29 @@ def process(file, list): reportphantomwarnings(warnings, f) else: if len(slashes) > 1: - report(slashes, "More than one / operator") - else: - (row, col), line = slashes[0] + if not multi_ok: + report(slashes, "More than one / operator per statement") + continue + intlong = [] + floatcomplex = [] + bad = [] + for lineno, what in warnings: + if what in ("int", "long"): + intlong.append(what) + elif what in ("float", "complex"): + floatcomplex.append(what) + else: + bad.append(what) + lastrow = None + for (row, col), line in slashes: + if row == lastrow: + continue + lastrow = row line = chop(line) if line[col:col+1] != "/": print "*** Can't find the / operator in line %d:" % row print "*", line continue - intlong = [] - floatcomplex = [] - bad = [] - for lineno, what in warnings: - if what in ("int", "long"): - intlong.append(what) - elif what in ("float", "complex"): - floatcomplex.append(what) - else: - bad.append(what) if bad: print "*** Bad warning for line %d:" % row, bad print "*", line |