-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] Behavior of os.path.join does not match documentation #77607
Comments
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 |
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? |
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." |
Hi, I'm working on it. I will provide the pull request within 3 days. |
Minimal changes that would largely reduce the likelihood of being misunderstood: Remove "intelligently" or replace "following" by "added after". |
This is a follow-up to python#100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in python#77607 and motivated the change in python#100811.
This is a follow-up to #100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in #77607 and motivated the change in #100811.
This is a follow-up to pythonGH-100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in pythonGH-77607 and motivated the change in pythonGH-100811. (cherry picked from commit 909a674) Co-authored-by: Shantanu <[email protected]>
This is a follow-up to pythonGH-100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in pythonGH-77607 and motivated the change in pythonGH-100811. (cherry picked from commit 909a674) Co-authored-by: Shantanu <[email protected]>
This is a follow-up to GH-100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in GH-77607 and motivated the change in GH-100811. (cherry picked from commit 909a674) Co-authored-by: Shantanu <[email protected]>
This is a follow-up to GH-100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in GH-77607 and motivated the change in GH-100811. (cherry picked from commit 909a674) Co-authored-by: Shantanu <[email protected]>
This is a follow-up to python#100811. One of the changes in that PR isn't accurate in that `os.path.join('', '')` will not end in a separator. This reverts that change to the previous wording that used "only", but explicitly calls out the case where the last part ends in a separator, which is what caused confusin in python#77607 and motivated the change in python#100811.
* main: pythongh-101440: fix json snippet error in logging-cookbook.rst (python#101439) pythongh-99276 - Updated Doc/faq/general.rst (python#101396) Add JOBS parameter to docs Makefile (python#101395) pythongh-98831: rewrite GET_LEN, GET_ITER, BEFORE_WITH and a few simple opcodes in the instruction definition DSL (python#101443) pythongh-77607: Improve accuracy of os.path.join docs (python#101406) Fixes typo in asyncio.TaskGroup context manager code example (python#101449) pythongh-98831: Clean up and add cache size static_assert to macro (python#101442) pythongh-99955: use SUCCESS/ERROR return values in optimizer and assembler. Use RETURN_IF_ERROR where appropriate. Fix a couple of bugs. (python#101412)
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: