This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Minor documentation bug with os.path.split
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: evaned, georg.brandl, jackdied, sandro.tosi
Priority: normal Keywords: patch

Created on 2009-09-02 20:35 by evaned, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue6825-py3k.patch sandro.tosi, 2010-10-07 22:32
issue6825-py3k-v2.patch sandro.tosi, 2010-10-08 17:20
Messages (6)
msg92180 - (view) Author: Evan Driscoll (evaned) Date: 2009-09-02 20:35
The documentation for os.path.split says, in part:

  "In nearly all cases, join(head, tail) equals path (the only 
  exception being when there were multiple slashes separating head
  from tail)."

But this is not quite true: that's not the *only* exception, at least
without a somewhat liberal definition of "equals".

This can also happen if os.altsep is used in the path being split, in
which case it will be replaced by os.sep:

>>> import ntpath
>>> path = "a/b"
>>> (head, tail) = ntpath.split(path)
>>> joined = ntpath.join(head, tail)
>>> joined == path
False
>>> joined
'a\\b'


[I only selected the versions that I actually verified, but I would
guess it's present in more.]
msg99931 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2010-02-23 16:29
how about "an equivalent path" instead of "equal path"?  The result of ntpath.join(ntpath.split(path)) should point to the same location even if it isn't literally the same string.
msg118148 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2010-10-07 22:32
Hello,
I find the proposed text change good, and so here's a patch to add that in a bit different format (sorry it's quite of a mess, but I took the occasion to wrap that paragraph to 80th column).

Regards,
Sandro
msg118159 - (view) Author: Evan Driscoll (evaned) Date: 2010-10-08 02:46
Hah, I totally forgot about this thing.

I'd suggest a change to the proposed patch. The patched version says:

  "In nearly all cases, ``join(head, tail)`` returns a location
   equivalent to *path* (the only exception being when there were 
   multiple slashes separating *head* from *tail*)."

Except now the parenthetical remark at the end of that sentence is a bit weird, because "a//a" != "a/a" is no longer an exception.

I'd suggest a wording such as one of the following, depending on where you want the emphasis (on the meaning of the return value of a path or on the actual contents of the return value as a string):

  "In all cases, ``join(head, tail)`` returns a location equivalent
   to *path*."

  "In most cases, ``join(head, tail)`` equals *path*; the
   exceptions to this are when there were multiple slashes
   separating *head* from *tail* or when *os.altsep* separators
   are replaced by *os.sep*."

The first suggestion could be followed by a remark "(but the strings may be unequal)" if you'd like.

I'd also replace "a location equivalent to" with "a path to the same location as" or something like that; "location" doesn't appear anywhere else on that page, and it seems slightly out of place to me.
msg118207 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2010-10-08 17:20
Hi Evan,
all your comments make sense, so I prepared a new patch about it.

I decided to go with the first option and adding a note about the possible different strings.

Regards,
Sandro
msg118624 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-14 06:46
Thanks, applied in r85453.
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51074
2010-10-14 06:46:17georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg118624
2010-10-08 17:20:53sandro.tosisetfiles: + issue6825-py3k-v2.patch

messages: + msg118207
versions: + Python 3.2, - Python 2.6
2010-10-08 02:46:19evanedsetmessages: + msg118159
2010-10-07 22:32:17sandro.tosisetfiles: + issue6825-py3k.patch

nosy: + sandro.tosi
messages: + msg118148

keywords: + patch
2010-02-23 16:29:03jackdiedsetnosy: + jackdied
messages: + msg99931
2009-09-02 20:35:21evanedcreate