[Python-checkins] CVS: python/dist/src/Tools/scripts fixdiv.py,1.2,1.3

Guido van Rossum gvanrossum@users.sourceforge.net
Sun, 02 Sep 2001 07:11:32 -0700


Update of /cvsroot/python/python/dist/src/Tools/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv16766

Modified Files:
	fixdiv.py 
Log Message:
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.


Index: fixdiv.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/fixdiv.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** fixdiv.py	2001/09/02 04:49:36	1.2
--- fixdiv.py	2001/09/02 14:11:30	1.3
***************
*** 63,66 ****
--- 63,67 ----
    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:
***************
*** 100,106 ****
  from pprint import pprint
  
  def main():
      try:
!         opts, args = getopt.getopt(sys.argv[1:], "h")
      except getopt.error, msg:
          usage(msg)
--- 101,109 ----
  from pprint import pprint
  
+ multi_ok = 1
+ 
  def main():
      try:
!         opts, args = getopt.getopt(sys.argv[1:], "hm")
      except getopt.error, msg:
          usage(msg)
***************
*** 110,113 ****
--- 113,119 ----
              print __doc__
              return
+         if o == "-m":
+             global multi_ok
+             multi_ok = 0
      if not args:
          usage("at least one file argument is required")
***************
*** 131,135 ****
  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("Try `%s -h' for more information.\n" % sys.argv[0])
  
--- 137,141 ----
  def usage(msg):
      sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
!     sys.stderr.write("Usage: %s [-m] warnings\n" % sys.argv[0])
      sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0])
  
***************
*** 198,204 ****
          else:
              if len(slashes) > 1:
!                 report(slashes, "More than one / operator")
!             else:
!                 (row, col), line = slashes[0]
                  line = chop(line)
                  if line[col:col+1] != "/":
--- 204,225 ----
          else:
              if len(slashes) > 1:
!                 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] != "/":
***************
*** 206,219 ****
                      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
--- 227,230 ----