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: Clarify docs of os.path.normpath()
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: docs@python, ezio.melotti, gsingh, loewis, pitrou, python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: easy

Created on 2013-03-14 09:41 by gsingh, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)
msg184152 - (view) Author: Gurmeet Singh (gsingh) Date: 2013-03-14 09:41
This is the first time I am creating an issue. I may be doing something wrong. I will correct that if you make me aware about it!

Issue with documentation:
Documentation page: http://docs.python.org/3/library/os.path.html
Entry: os.path.normpath(path)
Contention line: "It should be understood that this may change the meaning of the path if it contains symbolic links!"

Ambiguity Source: Contention line immediately follows the line "On Windows, it converts forward slashes to backward slashes." relating contention line to also windows.

Ambiguity: "I think" (i.e. I do not know for sure) that, the contention line should apply to all OS, not just windows. for example, .. after a symlink should, according to me, remove the symlink itself by the normpath function. This would be an incorrect behaviour of the normpath (I consider that incorrect). Hence, should be documented for all OS.
msg184216 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-03-15 06:22
> I will correct that if you make me aware about it!

Try to use meaningful titles, e.g. "Clarify docs of os.path.normpath()".  See http://docs.python.org/devguide/triaging.html for more informations.

Also if you could provide patches that would be even better.  The devguide explains how to make patches.


For this issue it might be enough to simply swap the two sentences.
msg184221 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-03-15 07:23
The question is what is the 'this' that may change the patch meaning. It does not seem to me that changing '/' to '\' would do that. So I suspect 'this' refers to 'collapsing'. If so, I suggest the entry be:

    Normalize a pathname (but not the case -- use normcase for that). This collapses redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. This collapsing may change the meaning of the path if it contains symbolic links!  On Windows, normpath also converts forward slashes to backward slashes.
msg184291 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-03-16 05:04
Your suggestion -- assuming it's accurate -- looks good to me, however I would get rid of the exclamation mark and move the link to normcase at the end:
"""
Normalize a pathname by collapsing redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. This collapsing may change the meaning of the path if it contains symbolic links.  On Windows, normpath also converts forward slashes to backward slashes.  normpath doesn't normalize the case -- use normcase for that.
"""
msg184333 - (view) Author: Gurmeet Singh (gsingh) Date: 2013-03-16 17:03
At the moment, I running late for creating a program - so I apologize that immediately I would not able to work on creating a patch. Later though I may be able to. I am sorry.

To avoid wasted work I think patch should be created only after someone (do not know who though!) has approved of the suggestions.

Thanks for the tips. I will read http://docs.python.org/devguide/triaging.html before posting next - but sorry, that I have posted many issues already without reading your response. 

__________________

You guys have both understood the issues I tried to say. 

The collapsing by '..' kills out sym link without realizing it is symlink - since it does not refer to file system - it is just a string manipulation utility (Again, I cannot commit on this since I have not read the source code or experimented this - it is an educated guess by reading only the docs).

So, I further suggest to add to the description by Ezio Melotti after the line "This collapsing may change the meaning of the path if it contains symbolic links.". We could add the following bracketed line "(since os.path.normpath is just string manipulation utility - unaware of the underlying file system)". This would remove the source of confusion, that we all here have got confused about.
msg184392 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-03-17 19:30
New changeset ff9636af9505 by Terry Jan Reedy in branch '3.2':
Issue #17415: Clarify 'this' referent by moving containing sentence just after
http://hg.python.org/cpython/rev/ff9636af9505

New changeset bceb81b0016e by Terry Jan Reedy in branch '2.7':
Issue #17415: Clarify 'this' referent by moving containing sentence just after
http://hg.python.org/cpython/rev/bceb81b0016e

New changeset 5b5a9bceb228 by Terry Jan Reedy in branch '3.2':
Issue #17415: Trim trailing whitespace
http://hg.python.org/cpython/rev/5b5a9bceb228

New changeset 44b9f59c6ea7 by Terry Jan Reedy in branch '2.7':
Issue #17415: Trim trailing whitespace
http://hg.python.org/cpython/rev/44b9f59c6ea7
msg184393 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-03-17 19:33
If foo is a symbolic link,  changing A/foo/../B to A/B could change the meaning, so I am sure the rewrite is correct. I used Ezio's version with a few more changes. I particular, I changed 'This collapsing', which is slightly awkward anyway, to 'This string manipulation', which addresses Gurmeet's last comment.
msg184396 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-03-17 20:23
os.path.normpath() works not only with strings but with bytes objects too.
msg184405 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-03-17 23:03
The top of the os doc makes it clear that path = byte string or unicode string and I meant 'string' in that generalized sense. I think 'string' is used that way elsewhere in the 3.x docs. I though of 'text manipulation', but as the doc again makes clear, unix byte string paths may not be 'text', which is why byte string paths are needed. That was my thought, anyway.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61617
2013-03-18 04:52:02terry.reedysetstatus: open -> closed
assignee: docs@python -> terry.reedy
stage: needs patch -> resolved
2013-03-17 23:03:30terry.reedysetmessages: + msg184405
2013-03-17 20:23:44serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg184396
2013-03-17 19:33:17terry.reedysetresolution: fixed
messages: + msg184393
2013-03-17 19:30:57python-devsetnosy: + python-dev
messages: + msg184392
2013-03-16 17:03:43gsinghsetmessages: + msg184333
2013-03-16 05:04:11ezio.melottisetmessages: + msg184291
2013-03-15 07:23:55terry.reedysetnosy: + loewis, pitrou
messages: + msg184221
2013-03-15 06:22:55ezio.melottisettitle: Documentation Ambiguity 1 -> Clarify docs of os.path.normpath()

keywords: + easy
nosy: + terry.reedy, ezio.melotti
versions: + Python 2.7, Python 3.2, Python 3.4
messages: + msg184216
stage: needs patch
2013-03-14 09:41:24gsinghcreate