
John Hennig jhen@gmx.net added the comment:
@Floris:
Not mentioning Path.resolve()'s behavior w.r.t. non-existing files since
that's documented in resolve() itself.
I don't see it mentioned in the documentation of `resolve()`, or anywhere else in the docs, that on Windows (but not on other platforms) `resolve()` does *not* resolve a relative path to an absolute path if the file does not exist. As opposed to `absolute()`, which works as expected on any platform.
Linux: ``` Python 3.6.9 (default, Oct 8 2020, 12:12:24) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information.
from pathlib import Path file = Path('new.txt') file.exists()
False
file.resolve()
PosixPath('/home/user/new.txt') ```
Windows: ``` Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
from pathlib import Path file = Path('new.txt') file.exists()
False
file.resolve()
WindowsPath('new.txt')
file.absolute()
WindowsPath('d:/home/new.txt')
file.touch() file.resolve()
WindowsPath('D:/home/new.txt')
file.unlink() file.resolve()
WindowsPath('new.txt')
```
---------- nosy: +John-Hennig
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue39090 _______________________________________