Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7a9598

Browse files
committed
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.
1 parent aaf80c8 commit e7a9598

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

Tools/scripts/fixdiv.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
multi-line statement, it's not clear whether both were executed. In
6363
practice, they usually are, so the default action is make the same
6464
recommendation for all / operators, based on the above criteria.
65+
The -m option issues warnings for these cases instead.
6566
6667
Notes:
6768
@@ -99,16 +100,21 @@
99100
import tokenize
100101
from pprint import pprint
101102

103+
multi_ok = 1
104+
102105
def main():
103106
try:
104-
opts, args = getopt.getopt(sys.argv[1:], "h")
107+
opts, args = getopt.getopt(sys.argv[1:], "hm")
105108
except getopt.error, msg:
106109
usage(msg)
107110
return 2
108111
for o, a in opts:
109112
if o == "-h":
110113
print __doc__
111114
return
115+
if o == "-m":
116+
global multi_ok
117+
multi_ok = 0
112118
if not args:
113119
usage("at least one file argument is required")
114120
return 2
@@ -130,7 +136,7 @@ def main():
130136

131137
def usage(msg):
132138
sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
133-
sys.stderr.write("Usage: %s warnings\n" % sys.argv[0])
139+
sys.stderr.write("Usage: %s [-m] warnings\n" % sys.argv[0])
134140
sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0])
135141

136142
PATTERN = ("^(.+?):(\d+): DeprecationWarning: "
@@ -197,24 +203,29 @@ def process(file, list):
197203
reportphantomwarnings(warnings, f)
198204
else:
199205
if len(slashes) > 1:
200-
report(slashes, "More than one / operator")
201-
else:
202-
(row, col), line = slashes[0]
206+
if not multi_ok:
207+
report(slashes, "More than one / operator per statement")
208+
continue
209+
intlong = []
210+
floatcomplex = []
211+
bad = []
212+
for lineno, what in warnings:
213+
if what in ("int", "long"):
214+
intlong.append(what)
215+
elif what in ("float", "complex"):
216+
floatcomplex.append(what)
217+
else:
218+
bad.append(what)
219+
lastrow = None
220+
for (row, col), line in slashes:
221+
if row == lastrow:
222+
continue
223+
lastrow = row
203224
line = chop(line)
204225
if line[col:col+1] != "/":
205226
print "*** Can't find the / operator in line %d:" % row
206227
print "*", line
207228
continue
208-
intlong = []
209-
floatcomplex = []
210-
bad = []
211-
for lineno, what in warnings:
212-
if what in ("int", "long"):
213-
intlong.append(what)
214-
elif what in ("float", "complex"):
215-
floatcomplex.append(what)
216-
else:
217-
bad.append(what)
218229
if bad:
219230
print "*** Bad warning for line %d:" % row, bad
220231
print "*", line

0 commit comments

Comments
 (0)