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: os.path.normpath doesn't normalize ../path/something.py
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.7, Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, purpleidea
Priority: normal Keywords:

Created on 2009-11-13 17:05 by purpleidea, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg95189 - (view) Author: James (purpleidea) Date: 2009-11-13 17:05
os.path.normpath doesn't normalize paths that start with ../
you would expect the final output line in the secpnd run to read:
"normpath: badnormpath.py" instead of: "normpath: ../tmp/badnormpath.py"

example:

james@home:~$ cd tmp/
james@home:~/tmp$ cat badnormpath.py 
#!/usr/bin/python

import os.path

print '__file__: %s' % __file__
print 'normpath: %s' % os.path.normpath(__file__)

james@home:~/tmp$ ./badnormpath.py 
__file__: ./badnormpath.py
normpath: badnormpath.py
james@home:~/tmp$ ./../tmp/badnormpath.py 
__file__: ./../tmp/badnormpath.py
normpath: ../tmp/badnormpath.py
james@home:~/tmp$
msg95199 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-11-13 20:27
normpath() doesn't look at the file system.  It cannot know that your
current directory is ~/tmp, so it cannot know that . and ../tmp are the
same directory.
msg95207 - (view) Author: James (purpleidea) Date: 2009-11-13 21:44
i looked at the source for normpath.
i know that it doesn't look at the filesystem.
assuming you're not currently sitting at the root directory, in all? 
cases ../xyz brings you back to where you started. we expect normpath to 
clean up a path string, collapsing '../' (as documented), perhaps either 
the docs should state otherwise, or this should collapse dirs as long as 
they are present in the path given to it ?

as an aside is there any reason why normpath shouldn't look at the 
filesystem and decide if it makes sense to collapse a leading '../' when 
this case arises ?
msg95237 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-11-14 11:45
If your current directory is (e.g.) /home/user, then ../xyz will not
"bring you back" to it.  (xyz/.. would.)
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51564
2009-11-14 11:45:57georg.brandlsetmessages: + msg95237
2009-11-13 21:44:34purpleideasetmessages: + msg95207
2009-11-13 20:27:37georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg95199

resolution: wont fix
2009-11-13 17:05:13purpleideacreate