Title: Remove import string in Tools/ directory
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: doerwalter Nosy List: doerwalter, gvanrossum, nnorwitz, rhettinger
Priority: normal Keywords: patch

Created on 2002-06-21 14:52 by doerwalter, last changed 2002-09-12 13:17 by gvanrossum. This issue is now closed.

File name Uploaded Description Edit
diff.txt doerwalter, 2002-06-21 14:52
diffnotes.txt rhettinger, 2002-09-09 04:03 Corrections and review notes
diff2.txt doerwalter, 2002-09-09 19:54
Messages (9)
msg40381 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-06-21 14:52
This patch replace string module functions with string
methods and removes the "import string" for the stuff
in the Tools directory. A few "import string"
statements are still remaining:

scripts/ still uses string.ascii_letters,
string.digits, etc.

modulator/ still uses string.letters and

freeze/win32.html still mentions the string module

idle/ still uses string.ascii_letters and

idle/ still uses string.uppercase,
string.lowercase and string.digits

idle/ still uses string.ascii_letters and

idle/ still uses string.ascii_letters
and string.digits

idle/ still uses string.capwords()

msg40382 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-09-08 04:53
Logged In: YES 

Let me know if you want this done.  If so, I'll give it a 
second check (line-by-line) for errors.
msg40383 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-09-08 04:57
Logged In: YES 

Good idea to give it a careful check. I'd suggest to let
Walter to check it in since he did the work though. Or you
two can race for it. :-)
msg40384 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-09-09 04:03
Logged In: YES 

Whew!  It takes just as long to check as 6000 line diff as it 
does to create the thing in the first place.

The patch is accepted and ready to commit after the 
following corrections and review notes are addressed.

Since several errors were syntactical, they could be caught 
by running the script.  I recommend that all of the scripts 
be run one time before a final commit.

Also, anoter additional check would be useful.  Everywhere 
a function defined the likes of _find=string.find, re-verify 
that every instance of _find was fixed-up (I cannot check 
this from the diff file).

Corrections and review notes (also attached as a separate 

In file:
Replace:  have = len(chars.expand(tabwidth))
With:  have = len(chars.expandtabs(tabwidth))

In file:
Replace: line.find('python') >= 0
With: 'python' in line

In file:           
Replace:  data = "\n".join("\n")
With:  data = "\n".join(lines)

In file:
Replace:  return len(str[self.stmt_start:i].expandtabs(,
With:  return len(str[self.stmt_start:i].expandtabs(\

In file:
Replace:  print file.ljust(file, maxlen),
With:  print file.ljust(maxlen),

In file:
Reverify propriety of substitution:  if ord(c)<=0x80 and 

In file:
Replace:  if sub.find('warning') >= 0: return 1
With:  if 'warning' in sub: return 1

In file:
Replace:  errors.append(''.join((email.strip()+': '
With:  errors.append(' '.join((email.strip()+': '

In file:
errors.append(''.join((email.strip()+': '+reason).split()))
errors.append(' '.join((email.strip()+': '+reason).split()))

In file:
Replace:  ! /usr/bin/env python
With:  #! /usr/bin/env python

In file:
Replace:  if line.find("python") < 0:
With:  if "python" in line:

In file:
I don't understand the <<<<<< additions

In file:
Replace:  split(e.split('/')
With:  e.split('/')

msg40385 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-09-09 19:54
Logged In: YES 

diff2.txt is a new version of the patch (against current CVS).

I rechecked the fixheader fix with:
for i in xrange(256):
   c = chr(i)
   if (ord(c)<=0x80 and c.isalnum()) != (c in
string.ascii_letters + string.digits): 
      print i,c
There are no differences.

> In file:
> Replace:  if line.find("python") < 0:
> With:  if "python" in line:

This should probably be:
    if "python" not in line:

> In file:
> I don't understand the <<<<<< additions

Ouch, that was a merge conflict.

OK, Raymond could you recheck if the new patch diff2.txt is
OK now? These mindless changes really are tricky! ;)

Unfortunately running the scripts isn't an option in most
cases: Some require Tk, some might expect certain files and
some might even transmogrify all the source files.

I changed a few tests
   line[:x] == ""

I rechecked the _find = string.find cases in idle/
and script/

If I'll get your OK I'll check this in.
msg40386 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-09-10 04:57
Logged In: YES 

In the interests of saving time and having maximum 
accuracy, I recommend reverting and then re-applying first 
patch and then making the changes on my list.  Try not to 
make any other changes.

It took half a day to thoroughly review that 6000 line diff.  
It doesn't make sense for me to re-check everything from 
scratch. To keep the integrity of the review, make as few 
changes as possible.  

Also, it does make sense for you to give a self-review to 
your final diff (remember, GvR believes in public floggings 
for those who break working code).

Here are a couple of fast checks:
-- scan the diff for ''.join and make sure it came from a join
(strdata, "")
-- grep the final files for >= 0: or < 0: to see if the 'in' 
operator applies.
-- grep the final files for expand( to make sure an 
expandtabs( was not missed.
-- grep the final files for join("\n"), join(" "), or join(' ') to see 
if there was an error moving the separator to the front

A slower self check is to read the diff file line-by-line and 
mentally recompute each change and compare with the 
actual change.   The diff review will certainly catch 
unintended changes like the merge conflict or the she-
bang change.

I know you can't run each script, but do as much as you 
can by importing each script to see if it gets a compilation 
error.  This won't catch runtime errors but it will catch 
syntax glitches.

One important group of scripts can be run.  Try to give 
IDLE a thorough exercise.

Then, when you're feeling brave, commit.

Good luck!
msg40387 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-09-11 20:48
Logged In: YES 

I rechecked the patch line-by-line and imported
every module that seemed to be importable
(and found a (last?) bug in bgen/bgen/,
so I finally checked it in as:

audiopy/audiopy 1.20
bgen/bgen/ 1.14
bgen/bgen/ 1.4
bgen/bgen/ 1.32
faqwiz/ 1.28
freeze/ 1.5
freeze/ 1.7
freeze/ 1.42
freeze/ 1.14
freeze/ 1.7
freeze/ 1.20
freeze/ 1.4
freeze/ 1.12
idle/ 1.20
idle/ 1.16
idle/ 1.12
idle/ 1.13
idle/ 1.13
idle/ 1.44
idle/ 1.10
idle/ 1.4
idle/ 1.5
idle/ 1.3
idle/ 1.2
idle/ 1.6
idle/ 1.10
idle/ 1.40
idle/ 1.8
idle/ 1.2
idle/ 1.3
idle/ 1.17
idle/ 1.8
idle/ 1.5
idle/ 1.2
modulator/ 1.5
modulator/ 1.10
modulator/ 1.4
scripts/ 1.8
scripts/ 1.3
scripts/ 1.12
scripts/ 1.5
scripts/ 1.11
scripts/ 1.10
scripts/ 1.5
scripts/ 1.15
scripts/ 1.7
scripts/ 1.5
scripts/ 1.8
scripts/ 1.10
scripts/ 1.7
scripts/ 1.5
scripts/ 1.6
scripts/ 1.5
scripts/ 1.6
scripts/ 1.11
scripts/ 1.2
scripts/ 1.5
scripts/ 1.9
scripts/ 1.6
scripts/ 1.3
scripts/ 1.10
scripts/ 1.15
unicode/ 1.12
versioncheck/ 1.3
versioncheck/ 1.4
webchecker/ 1.3
webchecker/ 1.9
webchecker/ 1.28
webchecker/ 1.10
webchecker/ 1.6

Waiting for the public floggings now...
msg40388 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-09-12 04:39
Logged In: YES 

Walter, can this be closed now?
msg40389 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-09-12 13:17
Logged In: YES 

I'd just like to say, thanks! to Walter and Raymond for
doing this thankless work. :-)
Date User Action Args
2002-06-21 14:52:34doerwaltercreate