New submission from Tzu-ping Chung <uranu...@gmail.com>:

The behaviour of os.path.abspath() and pathlib.Path.resolve() is a different 
when dealing with a path on a UNC share (on Windows):

    >>> import os, pathlib
    >>> path = pathlib.Path('Z:\foo')
    >>> path.resolve()
    WindowsPath('//host/share/foo')
    >>> os.path.abspath(path)
    'Z:\\foo'

This is not necessarily a problem by itself, just a consequence of calling 
different APIs underneath (although it probably worths a mention in 
documentation). The real problem is that the UNC path is not really useful 
anywhere in the Python standard library (AFAIK), and there’s no way to turn the 
it (back) into network drive once you call resolve(). The only way to get a 
network drive path is to

    >>> pathlib.Path(os.path.abspath(path))

Some possibile solutions:

1. Change the behaviour of resolve() to return the network drive path instead. 
This would be the most straightforward, API-wise, but is backward-incompatible, 
and maybe the original implementation did this on purpose?
2. Add a as_absolute() to pathlib.Path. On Windows this would mirror the result 
of os.path.abspath(); on POSIX this would probably be identical to resolve().
3. Add an argument to resolve()? This is essentially the same as 2., just 
interfaced differently.

----------
components: Library (Lib), Windows
messages: 309137
nosy: paul.moore, steve.dower, tim.golden, uranusjr, zach.ware
priority: normal
severity: normal
status: open
title: Result of pathlib.Path.resolve() with UNC path is not very useful
versions: Python 3.6

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

Reply via email to