This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eric.smith, eryksun, lutecki, serhiy.storchaka, smarie, veky, zbysz
Date 2021-11-26.21:02:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1637960579.7.0.984937100146.issue44452@roundup.psfhosted.org>
In-reply-to
Content
> and b / a gives me WindowsPath('/a/b'). So I'm like "ok, a seems
> like absolute, I will test for that" but on Windows a.is_absolute()
> is False.

Path.is_absolute() is true if a path has a `root` and, for a Windows path, also a `drive`.

In C++, the filesystem::path is_absolute() method is similar. In Windows it's true if both has_root_name() (i.e. a drive) and has_root_directory() are true. In POSIX it just depends on has_root_directory(). pathlib.Path is also consistent with C++ filesystem::path with regard to appending paths with the slash operator [1]. I would prefer for it to remain so.

FYI, in Windows, "/a/b" is resolved using the drive of the process current working directory, which may be a UNC path. The drive of a UNC path is the share path, such as "\\server\share". 

Another type of relative path in Windows is a drive-relative path, which applies to drive-letter drives only. For example:

    >>> Path('C:spam') / "eggs"
    WindowsPath('C:spam/eggs')
    >>> Path('C:spam') / "/eggs"
    WindowsPath('C:/eggs')

"C:spam" is relative to the current working directory on drive "C:". The API gets the working directory for the target drive either from the process current working directory, if it's a path on the target drive, or from an "=<drive letter>:" environment variable, such as "=Z:". (The Windows API allows environment variable names to begin with "=".) If the process current working directory is on a different drive, and the environment variable for the target drive isn't set, the API defaults to using the root directory on the target drive. Setting these per-drive working directory environment variables is up to the application. Python's os.chdir() supports them. 

---
[1] https://en.cppreference.com/w/cpp/filesystem/path/append
History
Date User Action Args
2021-11-26 21:02:59eryksunsetrecipients: + eryksun, eric.smith, zbysz, serhiy.storchaka, veky, smarie, lutecki
2021-11-26 21:02:59eryksunsetmessageid: <1637960579.7.0.984937100146.issue44452@roundup.psfhosted.org>
2021-11-26 21:02:59eryksunlinkissue44452 messages
2021-11-26 21:02:59eryksuncreate