Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.path.commonpath() not so common #83431

Closed
filipp mannequin opened this issue Jan 7, 2020 · 4 comments
Closed

os.path.commonpath() not so common #83431

filipp mannequin opened this issue Jan 7, 2020 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir

Comments

@filipp
Copy link
Mannequin

filipp mannequin commented Jan 7, 2020

BPO 39250
Nosy @zware, @Filipp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-01-07.20:45:15.710>
created_at = <Date 2020-01-07.20:27:13.303>
labels = ['3.8', '3.7', 'library']
title = 'os.path.commonpath() not so common'
updated_at = <Date 2020-01-07.20:45:15.709>
user = 'https://github.com/filipp'

bugs.python.org fields:

activity = <Date 2020-01-07.20:45:15.709>
actor = 'zach.ware'
assignee = 'none'
closed = True
closed_date = <Date 2020-01-07.20:45:15.710>
closer = 'zach.ware'
components = ['Library (Lib)']
creation = <Date 2020-01-07.20:27:13.303>
creator = 'filipp'
dependencies = []
files = []
hgrepos = []
issue_num = 39250
keywords = []
message_count = 4.0
messages = ['359535', '359537', '359541', '359542']
nosy_count = 2.0
nosy_names = ['zach.ware', 'filipp']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue39250'
versions = ['Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8']

@filipp
Copy link
Mannequin Author

filipp mannequin commented Jan 7, 2020

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.

@filipp filipp mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir labels Jan 7, 2020
@zware
Copy link
Member

zware commented Jan 7, 2020

I'm not seeing how /var has /var/log in common with /var/log and /var/log/nginx.

@filipp
Copy link
Mannequin Author

filipp mannequin commented Jan 7, 2020

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

@zware
Copy link
Member

zware commented Jan 7, 2020

No problem :)

@zware zware closed this as completed Jan 7, 2020
@zware zware closed this as completed Jan 7, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant