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.
Created on 2010年09月22日 15:22 by rgrig, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| os.path.join-doc.patch | r.david.murray, 2011年06月23日 01:19 | |||
| Messages (14) | |||
|---|---|---|---|
| msg117146 - (view) | Author: Radu Grigore (rgrig) | Date: 2010年09月22日 15:22 | |
The docs say that "the return value is the concatenation of path1, and optionally path2, etc., with exactly one directory separator (os.sep) inserted between components, unless path2 is empty."
But os.path.join('x','') returns 'x/' in which path1 and path2 *are* separated by exactly one os.sep, even though path2 is empty.
Either the docs or the implementation should be updated.
|
|||
| msg117153 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年09月22日 20:47 | |
Since changing the implementation would be a backward incompatible behavior change to a behavior that has existed for a long time, it's the docs that should be updated. |
|||
| msg117220 - (view) | Author: Brian Brazil (bbrazil) * | Date: 2010年09月23日 19:14 | |
The behaviour is a bit more nuanced:
>>> os.path.join('x', '')
'x/'
>>> os.path.join('x', '', 'y')
'x/y'
>>> os.path.join('x', '', 'y', '', '')
'x/y/'
>>> os.path.join('', 'x')
'x'
I'm unsure how to word this best, maybe "non-trailing empty paths are ignored"?
|
|||
| msg117810 - (view) | Author: Radu Grigore (rgrig) | Date: 2010年10月01日 15:53 | |
I would say something like the following. The function join(path1, path2) is almost like os.sep.join(path1, path2), but (1) trailing path separators in path1 are ignored and (2) the result is simply path2 when path2 is an absolute path. The call join(path1, path2, path3) is equivalent to join(join(path1, path2), path3), and similarly for more than three paths. |
|||
| msg118322 - (view) | Author: Brian Brazil (bbrazil) * | Date: 2010年10月10日 08:41 | |
That doesn't cover the os.path.join('', 'x') case, and I'm not sure it makes os.path.join('x//', 'y') clear - though that doesn't matter as much.
How about making (2) "the result is simply path2 when path1 is empty or path2 is an absolute path?
|
|||
| msg118371 - (view) | Author: Rafe Kettler (rafe.kettler) | Date: 2010年10月11日 15:49 | |
I think Brian's second solution ("the result is simply path2 when path1 is empty or path2 is an absolute path?") is a strong one. If that were tacked on towards the end it would add some clarity to the docs for people who will end up using this behavior or want a more in-depth explanation. At the same time, I think putting it towards the end (as more of a side note, like the bit about behavior on Windows with drive names) lets less sophisticated users (like me) ignore that piece of documentation.
|
|||
| msg118373 - (view) | Author: Radu Grigore (rgrig) | Date: 2010年10月11日 16:01 | |
Realizing I still don't know what os.join.path does, I looked at the source. The comment in posixpath.py is: # Ignore the previous parts if a part is absolute. # Insert a '/' unless the first part is empty or already ends in '/'. I find this clear and it directly corresponds to the implementation. On the other hand, the source of ntpath.join() is a nightmare, and there's no similarly simple comment there. |
|||
| msg118378 - (view) | Author: Rafe Kettler (rafe.kettler) | Date: 2010年10月11日 16:33 | |
Radu, while the comments are not as clear for ntpath, the behavior is the same. So, the comment you detailed from posixpath could be adapted to Windows by replacing '/' with 'a separator' or something of that nature. That said, the comment in posixpath could be adapted to clear english like so: join() inserts a separator unless the first part is empty or already ends in a separator. If a part is absolute, join() ignores the previous parts. |
|||
| msg121540 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2010年11月19日 15:39 | |
I think the comment is fine as is. +1 to adding your wording to the docs. |
|||
| msg121549 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年11月19日 16:43 | |
"first part" by itself sounds like there can only be two parts. How about 'inserts a separator between each pair of...' Also, what does 'absolute' mean on Windows? Does it include the drive? If so, the second sentence should probably say 'if a part starts with a separator...' (Assuming, of course, that that's how ntpath.join actually works). |
|||
| msg121550 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2010年11月19日 16:45 | |
Comment in ntpath.isabs: For Windows it is absolute if it starts with a slash or backslash (current volume), or if a pathname after the volume-letter-and-colon or UNC-resource starts with a slash or backslash. |
|||
| msg138846 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2011年06月23日 01:19 | |
Here is a patch that I think describes the algorithm correctly, based on the comments in the module, with a clarifying parenthetical to cover the non-obvious consequence of that algorithm. |
|||
| msg138858 - (view) | Author: Brian Brazil (bbrazil) * | Date: 2011年06月23日 07:34 | |
David's change sounds good to me. |
|||
| msg138885 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年06月24日 01:27 | |
New changeset 1e89444f4ebc by R David Murray in branch '2.7': #9921: clarify os.path.join joining algorithm http://hg.python.org/cpython/rev/1e89444f4ebc New changeset f5f5b715be7e by R David Murray in branch '3.2': #9921: clarify os.path.join joining algorithm http://hg.python.org/cpython/rev/f5f5b715be7e New changeset b6759568b812 by R David Murray in branch 'default': merge #9921: clarify os.path.join joining algorithm http://hg.python.org/cpython/rev/b6759568b812 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:06 | admin | set | github: 54130 |
| 2011年06月24日 01:28:21 | r.david.murray | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2011年06月24日 01:27:51 | python-dev | set | nosy:
+ python-dev messages: + msg138885 |
| 2011年06月23日 07:34:30 | bbrazil | set | messages: + msg138858 |
| 2011年06月23日 01:19:30 | r.david.murray | set | files:
+ os.path.join-doc.patch messages: + msg138846 versions: + Python 3.3, - Python 3.1 |
| 2011年05月20日 03:20:07 | r.david.murray | link | issue12104 superseder |
| 2010年11月19日 16:45:29 | eric.araujo | set | messages: + msg121550 |
| 2010年11月19日 16:43:11 | r.david.murray | set | messages: + msg121549 |
| 2010年11月19日 15:39:11 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg121540 keywords: + patch stage: needs patch -> patch review |
| 2010年11月19日 15:37:15 | eric.araujo | set | messages: - msg118372 |
| 2010年10月11日 16:51:24 | rgrig | set | nosy:
- rgrig |
| 2010年10月11日 16:33:10 | rafe.kettler | set | messages: + msg118378 |
| 2010年10月11日 16:01:03 | rgrig | set | messages: + msg118373 |
| 2010年10月11日 15:58:05 | rgrig | set | messages: + msg118372 |
| 2010年10月11日 15:49:03 | rafe.kettler | set | nosy:
+ rafe.kettler messages: + msg118371 |
| 2010年10月10日 08:41:42 | bbrazil | set | messages: + msg118322 |
| 2010年10月01日 15:53:26 | rgrig | set | messages: + msg117810 |
| 2010年09月23日 19:14:50 | bbrazil | set | nosy:
+ bbrazil messages: + msg117220 |
| 2010年09月22日 20:47:46 | r.david.murray | set | assignee: docs@python components: + Documentation, - Library (Lib) versions: + Python 3.2 nosy: + r.david.murray, docs@python messages: + msg117153 stage: needs patch |
| 2010年09月22日 15:22:55 | rgrig | create | |