Author larry
Recipients amaury.forgeotdarc, eric.smith, larry, mhammond, paul.moore
Date 2009-05-05.02:34:49
SpamBayes Score 2.17137e-10
Marked as misclassified No
Message-id <1241490897.77.0.0648972015658.issue5799@psf.upfronthosting.co.za>
In-reply-to
Content
Sweet jumping rhubarb!  I didn't know about this "for ...: else:"
construct in Python.  When I was editing it I thought it was my editor
stumbling over a tab, and the "else" went with the "if" *inside* the
"for".  You're absolutely right that the current code is utter nonsense;
the "i += 1" gets overwritten immediately by the for loop.

On the other hand: the original code is wrong too.
  for i in whatever:
    something()
  else:
    i += 1
If the for loop is not executed, "i" is undefined, so adding 1 to it is
a runtime error.

Then again!  In the existing code the loop always executes at least
once, because it's iterating over the split of the absolute path, rather
than starting at the root of the current drive.  So the "else:" is
unnecessary.

What the "i += 1" is *probably* trying to do is fix this bug:
  >>> ntpath.relpath("/foo/bar/bat", "/")
  "../foo/bar/bat"
If the lists the for loop was examining skipped the drive letter (or UNC
path), the for loop wouldn't exit.  Maybe they used to have "i = 0"
above the loop or something, in which case this would probably have worked.

Sadly this bug is in both my version and the current version.

I will fix this bug, add a test case, and file a new patch, hopefully
tonight.
History
Date User Action Args
2009-05-05 02:34:59larrysetrecipients: + larry, mhammond, paul.moore, amaury.forgeotdarc, eric.smith
2009-05-05 02:34:57larrysetmessageid: <1241490897.77.0.0648972015658.issue5799@psf.upfronthosting.co.za>
2009-05-05 02:34:52larrylinkissue5799 messages
2009-05-05 02:34:50larrycreate