[New-bugs-announce] [issue32434] pathlib.WindowsPath.reslove(strict=False) returns absoulte path only if at least one component exists
report at bugs.python.org
Wed Dec 27 15:13:36 EST 2017
New submission from Martin Liska <juggzor at 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.
On a system with an existing, but empty directory C:\Test.
Running the interpreter at C:\ resolve behaves like so:
When running the interpreter inside C:\Test it instead behaves in the following manner:
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)
title: pathlib.WindowsPath.reslove(strict=False) returns absoulte path only if at least one component exists
versions: Python 3.6
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce