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.
This commit is contained in:
Guido van Rossum 2001-09-02 14:11:30 +00:00
parent aaf80c8c87
commit e7a95983b0

View file

@ -62,6 +62,7 @@ There are several possible recommendations and observations:
multi-line statement, it's not clear whether both were executed. In multi-line statement, it's not clear whether both were executed. In
practice, they usually are, so the default action is make the same practice, they usually are, so the default action is make the same
recommendation for all / operators, based on the above criteria. recommendation for all / operators, based on the above criteria.
The -m option issues warnings for these cases instead.
Notes: Notes:
@ -99,9 +100,11 @@ import re
import tokenize import tokenize
from pprint import pprint from pprint import pprint
multi_ok = 1
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "h") opts, args = getopt.getopt(sys.argv[1:], "hm")
except getopt.error, msg: except getopt.error, msg:
usage(msg) usage(msg)
return 2 return 2
@ -109,6 +112,9 @@ def main():
if o == "-h": if o == "-h":
print __doc__ print __doc__
return return
if o == "-m":
global multi_ok
multi_ok = 0
if not args: if not args:
usage("at least one file argument is required") usage("at least one file argument is required")
return 2 return 2
@ -130,7 +136,7 @@ def main():
def usage(msg): def usage(msg):
sys.stderr.write("%s: %s\n" % (sys.argv[0], 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]) sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0])
PATTERN = ("^(.+?):(\d+): DeprecationWarning: " PATTERN = ("^(.+?):(\d+): DeprecationWarning: "
@ -197,24 +203,29 @@ def process(file, list):
reportphantomwarnings(warnings, f) reportphantomwarnings(warnings, f)
else: else:
if len(slashes) > 1: if len(slashes) > 1:
report(slashes, "More than one / operator") if not multi_ok:
else: report(slashes, "More than one / operator per statement")
(row, col), line = slashes[0] 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) line = chop(line)
if line[col:col+1] != "/": if line[col:col+1] != "/":
print "*** Can't find the / operator in line %d:" % row print "*** Can't find the / operator in line %d:" % row
print "*", line print "*", line
continue 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: if bad:
print "*** Bad warning for line %d:" % row, bad print "*** Bad warning for line %d:" % row, bad
print "*", line print "*", line