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: [doc] Behavior of os.path.join does not match documentation
Type: behavior Stage: patch review
Components: Documentation, Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: DonnaDia, Michael Klatt, Rainald Koch, SilentGhost, docs@python, zach.ware
Priority: normal Keywords: easy, patch

Created on 2018-05-04 18:39 by Michael Klatt, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 28003 open DonnaDia, 2021-08-27 18:18
Messages (5)
msg316184 - (view) Author: Michael Klatt (Michael Klatt) Date: 2018-05-04 18:39
The behavior of os.path.join() regarding path separators does not match the documentation. This affects Python 3.6, and goes back to at least Python 2.7.

From the documenation: 

"The return value is the concatenation of path and any members of *paths with exactly one directory separator (os.sep) following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty."

To me, this means that join will remove extraneous separators from the path, and that the only way to produce a trailing separator is to use join "" as the final path segment.

I expect `os.path.join("/abc//", "def/")` to produce the string "/abc/def" based on the documentation, but what it actually produces is "abc//def/".
msg316194 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2018-05-05 04:12
your example actually produces '/abc//def/'.

However, I'm not sure where do you get the idea that it should clean up internal directory separators or do anything at all with the strings in paths. To me it reads like it's concatenating arguments skipping over the empty ones unless it's also the last one. 

In any case, what would you propose to fix the language to describe the behaviour more clear?
msg316223 - (view) Author: Michael Klatt (Michael Klatt) Date: 2018-05-05 23:58
For me, the ambiguity is due to the phrases "exactly one directory separator" and "the only way to produce a trailing separator".

I would suggest:

"The return value is the concatenation of path and any members of *paths so that there is a directory separator (os.sep) following each part except the last. An empty part is ignored unless it is the last part, in which case the result will end in a separator."

Or:

"The return value is the concatenation of path and any members of *paths such that there is guaranteed to be a directory separator (os.sep) following each part except the last. An empty part is ignored unless it is the last part, in which case the result will end in a separator."
msg400436 - (view) Author: Diana (DonnaDia) * Date: 2021-08-27 18:02
Hi, I'm working on it. I will provide the pull request within 3 days.
msg400903 - (view) Author: Rainald Koch (Rainald Koch) Date: 2021-09-02 08:33
Minimal changes that would largely reduce the likelihood of being misunderstood: Remove "intelligently" or replace "following" by "added after".
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77607
2021-09-02 08:33:07Rainald Kochsetnosy: + Rainald Koch
messages: + msg400903
2021-08-31 18:39:48zach.waresetnosy: + zach.ware
2021-08-27 18:18:28DonnaDiasetkeywords: + patch
stage: patch review
pull_requests: + pull_request26445
2021-08-27 18:02:05DonnaDiasetnosy: + DonnaDia
messages: + msg400436
2021-08-09 21:03:07iritkatrielsetkeywords: + easy
title: Behavior of os.path.join does not match documentation -> [doc] Behavior of os.path.join does not match documentation
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.4, Python 3.5, Python 3.6
2018-05-05 23:58:10Michael Klattsetmessages: + msg316223
2018-05-05 04:12:33SilentGhostsetnosy: + SilentGhost
messages: + msg316194
2018-05-04 18:39:06Michael Klattcreate