classification
Title: No error message in joining two root directories
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Bin Hu, eryksun
Priority: normal Keywords:

Created on 2019-07-25 22:08 by Bin Hu, last changed 2019-07-26 06:31 by eryksun. This issue is now closed.

Messages (2)
msg348457 - (view) Author: Bin Hu (Bin Hu) Date: 2019-07-25 22:08
Two root directories shall not be joined in the first place. But, when such a command is passed, os.path.join() module should give a warning message instead of just keeping the second argument being passed as the output. 

Python 3.7.3 (default, Mar 27 2019, 16:54:48)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from os import path

In [2]: a = '/tmp'

In [3]: b = '/data'

In [4]: print(path.join(a, b))
/data

In [5]: b = 'data'

In [6]: print(path.join(a, b))
/tmp/data
msg348468 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-07-26 06:31
The behavior in question is documented as follows: "If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component."

In Windows, this is extended to support drives and the six file-path types:

Absolute:

    DOS-Drive - C:\spam
    UNC       - \\localhost\C$\spam
    Device    - \\.\C:\spam
              - \\?\C:\spam

Hybrid [1]:

    DOS-Drive - C:spam
    Rooted    - \spam

Relative      - spam

Python extends the notion of a drive to UNC shares and devices [2]. join() handles all components with a drive as absolute. A rooted component that lacks a drive is not absolute, so it replaces only the root path of previous components, not the drive.

---

[1] os.path.isabs mistakenly classifies rooted paths as absolute, but they're relative to the working drive. pathlib.Path.is_absolute gets it right.

[2] There are unresolved issues with device paths. For example, "\\?\C:" is mistakenly handled as a drive-relative path, and the semantics of the "UNC" device and "Global" link aren't implemented.
History
Date User Action Args
2019-07-26 06:31:25eryksunsetstatus: open -> closed

type: behavior
components: + Library (Lib), - Extension Modules

nosy: + eryksun
messages: + msg348468
resolution: not a bug
stage: resolved
2019-07-25 22:08:27Bin Hucreate