New submission from Andy Maier <andreas.r.ma...@gmx.de>:

I found that os.path.relpath() on Windows raises ValueError when the path and 
the start path are on different drives. This is to be expected, as there is no 
single root on Windows.

On Python 3.7, the behavior is:

>>> os.path.relpath('c:/abc', 'a:/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\Python\Python37\lib\ntpath.py", line 564, in relpath
    path_drive, start_drive))
ValueError: path is on mount 'c:', start on mount 'a:'

The issue is that this ValueError and the reasons for it are not mentioned at 
all in the documentation for os.path.relpath(). Other os.path functions do 
document specific behaviors for different drives on Windows, for example 
os.path.commonpath(), so there is a precedence for documenting this. Also, it 
should be normal to document the possible exceptions that can be raised.

I did read https://bugs.python.org/issue7195 from 2009 where the original issue 
discussed also lead to a request to update the documentation of 
os.path.relpath() to show the ValueError for this case, but that angle of the 
issue ended up being ignored back then, unfortunately.

My suggestion is to add something like the following sentence the documentation:

"On Windows, ValueError is raised when path and start are on different drives."

----------
assignee: docs@python
components: Documentation
messages: 376057
nosy: andymaier, docs@python
priority: normal
severity: normal
status: open
title: os.path.relpath does not document ValueError on Windows with different 
drives
versions: Python 3.7

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

Reply via email to