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.

Author andymaier
Recipients andymaier, docs@python
Date 2020-08-29.06:15:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1598681705.55.0.359436315051.issue41661@roundup.psfhosted.org>
In-reply-to
Content
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."
History
Date User Action Args
2020-08-29 06:15:05andymaiersetrecipients: + andymaier, docs@python
2020-08-29 06:15:05andymaiersetmessageid: <1598681705.55.0.359436315051.issue41661@roundup.psfhosted.org>
2020-08-29 06:15:05andymaierlinkissue41661 messages
2020-08-29 06:15:04andymaiercreate