This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.commonpath() not so common
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: filipp, zach.ware
Priority: normal Keywords:

Created on 2020-01-07 20:27 by filipp, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg359535 - (view) Author: Filipp Lepalaan (filipp) Date: 2020-01-07 20:27
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.
msg359537 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2020-01-07 20:33
I'm not seeing how `/var` has `/var/log` in common with `/var/log` and `/var/log/nginx`.
msg359541 - (view) Author: Filipp Lepalaan (filipp) Date: 2020-01-07 20:43
Hi Zach!

You're absolutely right. Forgive my ignorance. Too much staring at the trees and not seeing the forest (or vice versa).

commonpath() works as advertised. I'm just looking for something different.

Sorry for the false alarm. You can close this issue
msg359542 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2020-01-07 20:45
No problem :)
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83431
2020-01-07 20:45:15zach.waresetstatus: open -> closed
resolution: works for me
messages: + msg359542

stage: resolved
2020-01-07 20:43:15filippsetmessages: + msg359541
2020-01-07 20:33:39zach.waresetnosy: + zach.ware
messages: + msg359537
2020-01-07 20:27:13filippcreate