[Python-Dev] os.path.commonprefix breakage (original) (raw)

Greg Stein gstein@lyra.org
Thu, 17 Aug 2000 00:01:22 -0700


os.path.split('/foo/bar/') ('/foo/bar', '')

Jamming a trailing slash on the end is a bit wonky. I'm with Skip on saying that the slash should probably not be appended. It gives funny behavior with the split. Users should use .join() to combine the resulting with something else.

The removal of a prefix is an interesting issue. No opinions there.

Cheers, -g

On Thu, Aug 17, 2000 at 01:32:25PM +1000, Mark Hammond wrote:

Hi, I believe that Skip recently made a patch to os.path.commonprefix to only return the portion of the common prefix that corresponds to a directory.

I have just dicovered some code breakage from this change. On 1.5.2, the behaviour was: >>> os.path.commonprefix(["../foo/bar", "../foo/spam"]) '../foo/' While since the change we have: '../foo' Note that the trailing slash has been dropped. The code this broke did similar to: prefix = os.path.commonprefix(files) for file in files: tailportion = file[len(prefix):] In 1.6, the "tailportion" result looks like an absolute path "/bar" and "/spam", respectively. The intent was obviously to get absolute path names back ("bar" and "spam") The code that broke is not mine, so you can safely be horrified at how broken it is :-) The point, however, is that code like this does exist out there. I'm obviously going to change the code that broke, and don't have time to look into the posixpath.py code - but is this level of possible breakage acceptable? Thanks, Mark.


Python-Dev mailing list Python-Dev@python.org http://www.python.org/mailman/listinfo/python-dev

-- Greg Stein, http://www.lyra.org/