[issue41661] os.path.relpath does not document ValueError on Windows with different drives

New submission from Andy Maier andreas.r.maier@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 report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Change by Karthikeyan Singaravelan tir.karthi@gmail.com:
---------- components: +Windows nosy: +eryksun, paul.moore, steve.dower, tim.golden, zach.ware type: -> behavior
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Eryk Sun eryksun@gmail.com added the comment:
The suggested documentation change looks good to me.
---------- type: behavior -> enhancement versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.7
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Change by Zackery Spytz zspytz@gmail.com:
---------- keywords: +patch nosy: +ZackerySpytz nosy_count: 7.0 -> 8.0 pull_requests: +24080 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25346
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Steve Dower steve.dower@python.org added the comment:
New changeset 67c0b3d89c4da9750fdb43fc66d3924681b22d2e by Zackery Spytz in branch 'master': bpo-41661: Document os.path.relpath() exception on Windows with different drives (GH-25346) https://github.com/python/cpython/commit/67c0b3d89c4da9750fdb43fc66d3924681b...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- nosy: +miss-islington nosy_count: 8.0 -> 9.0 pull_requests: +24100 pull_request: https://github.com/python/cpython/pull/25366
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +24101 pull_request: https://github.com/python/cpython/pull/25367
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Change by Steve Dower steve.dower@python.org:
---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset de06baa9de109a00c26de0dc5a248fe7aafe09f5 by Miss Islington (bot) in branch '3.9': bpo-41661: Document os.path.relpath() exception on Windows with different drives (GH-25346) https://github.com/python/cpython/commit/de06baa9de109a00c26de0dc5a248fe7aaf...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________

Łukasz Langa lukasz@langa.pl added the comment:
New changeset b570feaa9c6039b9d89cdf854a5fb388872eb38e by Miss Islington (bot) in branch '3.8': bpo-41661: Document os.path.relpath() exception on Windows with different drives (GH-25346) (#25367) https://github.com/python/cpython/commit/b570feaa9c6039b9d89cdf854a5fb388872...
---------- nosy: +lukasz.langa
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue41661 _______________________________________
participants (7)
-
Andy Maier
-
Eryk Sun
-
Karthikeyan Singaravelan
-
miss-islington
-
Steve Dower
-
Zackery Spytz
-
Łukasz Langa