classification
Title: os.path.join should call os.path.normpath on result
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: loewis, michael.foord
Priority: normal Keywords: easy

Created on 2009-08-22 21:58 by michael.foord, last changed 2009-08-22 22:48 by michael.foord. This issue is now closed.

Messages (3)
msg91877 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-08-22 21:58
os.path.join has very basic behavior in the handling of '..'

>>> import os
>>> os.path.join('/foo', '..')
'/foo/..'

For some usecases (comparing paths for example) this is not useful and
you have to manually call normpath on the results:

>>> os.path.normpath(os.path.join('/foo', '..'))
'/'

Because of this code gets littered with annoyingly long chained calls
which are a pain to both read and write.

Is there any problem with join always calling normpath on it's result?
msg91879 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-08-22 22:36
> Is there any problem with join always calling normpath on it's result?

Yes. If /usr/local/bin was a symlink to /net/x86, then
/usr/local/bin/../lib might not be /usr/local/lib, but /net/lib. So
calling normpath in the presence of symlinks might be incorrect.
msg91881 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-08-22 22:48
Damn. :-)

Detecting the case where the normpath'd location is the same means
hitting the filesystem - and the current version just does string
manipulation so it doesn't seem like an acceptable change.

Still, compared to other languages the file handling in Python (spread
across os, os.path, shutil, stat) is clunky and verbose. Fixing that
means duplicating this functionality which makes it unlikely that we'll
get it in the standard library.
History
Date User Action Args
2009-08-22 22:48:40michael.foordsetstatus: open -> closed
resolution: wont fix
messages: + msg91881
2009-08-22 22:36:28loewissetnosy: + loewis
title: os.path.join should call os.path.normpath on result -> os.path.join should call os.path.normpath on result
messages: + msg91879
2009-08-22 21:58:19michael.foordcreate