Larry Hastings <la...@hastings.org> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5799>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to