Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def isabs(s):

# Join two (or more) paths.
def join(path, *paths):
"""Join two or more pathname components, inserting '\\' as needed.
If any component is an absolute path, all previous path components
will be discarded. An empty last part will result in a path that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ntpath, "absolute path" means a path with a root, such as "\bar". If this path does not have a drive letter, then the previous drive letter (if any) is retained. So it's not right to say that all previous components will be discarded -- it's a little more subtle than that!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification! I made a change to be more descriptive, let me know if it still needs work.

ends with a separator."""
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
Expand Down
14 changes: 7 additions & 7 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ def isabs(s):
# Ignore the previous parts if a part is absolute.
# Insert a '/' unless the first part is empty or already ends in '/'.

def join(a, *p):
def join(path, *paths):
"""Join two or more pathname components, inserting '/' as needed.
If any component is an absolute path, all previous path components
will be discarded. An empty last part will result in a path that
ends with a separator."""
a = os.fspath(a)
sep = _get_sep(a)
path = a
path = os.fspath(path)
sep = _get_sep(path)
path = path
try:
if not p:
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
for b in map(os.fspath, p):
for b in map(os.fspath, paths):
if b.startswith(sep):
path = b
elif not path or path.endswith(sep):
path += b
else:
path += sep + b
except (TypeError, AttributeError, BytesWarning):
genericpath._check_arg_types('join', a, *p)
genericpath._check_arg_types('join', path, *paths)
raise
return path

Expand Down