New submission from Filipp Lepalaan <fil...@mac.com>:

The documentation describes os.path.commonpath() as:

"Return the longest common sub-path of each pathname in the sequence paths. 
Raise ValueError if paths contain both absolute and relative pathnames, the 
paths are on the different drives or if paths is empty. Unlike commonprefix(), 
this returns a valid path."

However, in practice the function seems to always return the *shortest* common 
path. Steps to reproduce:

import os.path
paths = ['/var', '/var/log', '/var/log/nginx']
os.path.commonpath(paths)

Expected results:
'/var/log'

Actual results:
'/var'

I've tried this with Python 3.5, 3.6, 3.7 and 3.8.1 on both MacOS and 
Debian/Linux and the results are consistent.

----------
components: Library (Lib)
messages: 359535
nosy: filipp
priority: normal
severity: normal
status: open
title: os.path.commonpath() not so common
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39250>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to