[New-bugs-announce] [issue39250] os.path.commonpath() not so common

Filipp Lepalaan report at bugs.python.org
Tue Jan 7 15:27:13 EST 2020


New submission from Filipp Lepalaan <filipp at 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 <report at bugs.python.org>
<https://bugs.python.org/issue39250>
_______________________________________


More information about the New-bugs-announce mailing list