summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-02 14:11:30 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-02 14:11:30 (GMT)
commite7a95983b0cd2e2b5275317a4d930b3b66c648e6 (patch)
treee54d8facc49176c28a57396779ff1d02c271792d
parentaaf80c8c8710ee839061478ebb48b90fdc6c23d2 (diff)
downloadcpython-e7a95983b0cd2e2b5275317a4d930b3b66c648e6.zip
cpython-e7a95983b0cd2e2b5275317a4d930b3b66c648e6.tar.gz
cpython-e7a95983b0cd2e2b5275317a4d930b3b66c648e6.tar.bz2
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.
-rwxr-xr-xTools/scripts/fixdiv.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/Tools/scripts/fixdiv.py b/Tools/scripts/fixdiv.py
index 382503a..616622b 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