◐ Shell
clean mode source ↗

GH-104996: Implement path joining algorithm in pathlib by barneygale · Pull Request #105484 · python/cpython

I'm not thrilled about duplicating the code from ntpath.join(). Have you considered adding an ntpath.splitseq(sequence) function that returns (drive, root, path_list)? Then ntpath.join() could be implemented as follows:

def join(path, *paths):
    paths = [os.fspath(path), *paths]
    if isinstance(paths[0], bytes):
        path = b''
        sep = b'\\'
        seps = b'\\/'
        colon = b':'
    else:
        path = ''
        sep = '\\'
        seps = '\\/'
        colon = ':'
    try:
        drive, root, path_list = splitseq(paths)
        for p in path_list:
            if path and path[-1] not in seps:
                path += sep
            path += p
        # If needed, add a separator between a UNC drive and path.
        if path and not root and drive and drive[-1:] != colon:
            return drive + sep + path
        return drive + root + path
    except (TypeError, AttributeError, BytesWarning):
        genericpath._check_arg_types('join', *paths)
        raise