Author skip.montanaro
Recipients skip.montanaro
Date 2008-12-27.04:00:32
SpamBayes Score 4.34097e-13
Marked as misclassified No
Message-id <1230350435.61.0.221193783724.issue4755@psf.upfronthosting.co.za>
In-reply-to
Content
os.path.commonprefix returns the common prefix of a list of paths taken character-by-character.  This can 
return invalid paths.  For example, os.path.commonprefix(["/export/home/dave", "/etc/passwd"]) will return "/e", which likely has no meaning as a path, at least in the context of the input list.

Ideally, os.path.commonprefix would operate component-by-component, but people rely on the existing 
character-by-character operation, so it has been so far impossible to change semantics.  There are several 
possible ways to solve this problem.  One, change how commonprefix behaves.  Two, add a flag to 
commonprefix to allow it to operate component-by-component if desired.  Three, add a new function to 
os.path.

I personally prefer the first option.  Aside from the semantic change though, it presents the problem of 
where to put the old definition of commonprefix.  It's clearly of some use or people wouldn't have co-
opted it for non-filesystem use.  It could go in the string module, but that's been living a life in limbo 
since the creation of string methods.  People have been loathe to add new functionality there.  The second 
option seems to me like would just be a hack on top of already broken behavior and probably require the 
currently slightly broken behavior as the default to boot, so I won't go there.  Since option one is 
perhaps not going to be available to me, I've implemented the third option as a new function, 
commonpathprefix.  See the attached patch.  It includes test cases and documentation changes.
History
Date User Action Args
2008-12-27 04:00:35skip.montanarosetrecipients: + skip.montanaro
2008-12-27 04:00:35skip.montanarosetmessageid: <1230350435.61.0.221193783724.issue4755@psf.upfronthosting.co.za>
2008-12-27 04:00:34skip.montanarolinkissue4755 messages
2008-12-27 04:00:33skip.montanarocreate