New submission from Martin Liska <jugg...@gmail.com>: The documentation for pathlib.Path.resolve says: "Make the path absolute, resolving any symlinks."
On Windows, the behavior doesn't always match the first part of the statement. Example: On a system with an existing, but empty directory C:\Test. Running the interpreter at C:\ resolve behaves like so: >>> os.path.realpath(r'Test\file') 'C:\\Test\\file' >>> WindowsPath(r'Test\file').resolve(strict=False) WindowsPath('C:/Test/file') When running the interpreter inside C:\Test it instead behaves in the following manner: >>> os.path.realpath('file') 'C:\\Test\\file' >>> WindowsPath('file').resolve(strict=False) WindowsPath('file') Resolving a path object specifying a non-existent relative path results in an identical (relative) path object. This is also inconsistent with the behavior of os.path.realpath as demonstrated. The root of the issue is in the pathlib._WindowsFlavour.resolve method at lines 193, 199 and 201. If at least one component of the path gets resolved at line 193 by the expression self._ext_to_normal(_getfinalpathname(s)), the path returned at line 201 will be joined from the absolute, resolved part and the unresolved remained. If none of the components get resolved then the path will be returned at line 199 as passed into the function. ---------- components: Library (Lib) messages: 309102 nosy: mliska priority: normal severity: normal status: open title: pathlib.WindowsPath.reslove(strict=False) returns absoulte path only if at least one component exists type: behavior versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32434> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com