Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error message in joining two root directories #81867

Closed
BinHu mannequin opened this issue Jul 25, 2019 · 2 comments
Closed

No error message in joining two root directories #81867

BinHu mannequin opened this issue Jul 25, 2019 · 2 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@BinHu
Copy link
Mannequin

BinHu mannequin commented Jul 25, 2019

BPO 37686
Nosy @eryksun

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-07-26.06:31:25.830>
created_at = <Date 2019-07-25.22:08:27.591>
labels = ['3.7', 'invalid', 'type-bug', 'library']
title = 'No error message in joining two root directories'
updated_at = <Date 2019-07-26.06:31:25.816>
user = 'https://bugs.python.org/BinHu'

bugs.python.org fields:

activity = <Date 2019-07-26.06:31:25.816>
actor = 'eryksun'
assignee = 'none'
closed = True
closed_date = <Date 2019-07-26.06:31:25.830>
closer = 'eryksun'
components = ['Library (Lib)']
creation = <Date 2019-07-25.22:08:27.591>
creator = 'Bin Hu'
dependencies = []
files = []
hgrepos = []
issue_num = 37686
keywords = []
message_count = 2.0
messages = ['348457', '348468']
nosy_count = 2.0
nosy_names = ['eryksun', 'Bin Hu']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue37686'
versions = ['Python 3.7']

@BinHu
Copy link
Mannequin Author

BinHu mannequin commented Jul 25, 2019

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

@BinHu BinHu mannequin added extension-modules C modules in the Modules dir 3.7 (EOL) end of life labels Jul 25, 2019
@eryksun
Copy link
Contributor

eryksun commented Jul 26, 2019

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.

@eryksun eryksun added stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Jul 26, 2019
@eryksun eryksun closed this as completed Jul 26, 2019
@eryksun eryksun added invalid type-bug An unexpected behavior, bug, or error labels Jul 26, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant