Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c903e6

Browse files
committed
Issue #13959: Continue to try to accomodate altsep in importlib by not
ignoring altsep if it already exists on a path when doing a join.
1 parent ce9bb9e commit 5c903e6

2 files changed

Lines changed: 2988 additions & 2971 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ def _r_long(int_bytes):
6161
return x
6262

6363

64-
# XXX Optimize for single-separator OSs by having two versions of this function
65-
# and choosing in _setup().
66-
def _path_join(*args):
64+
def _path_join(*path_parts):
6765
"""Replacement for os.path.join()."""
68-
return path_sep.join(x[:-len(path_sep)] if x.endswith(path_sep) else x
69-
for x in args if x)
66+
new_parts = []
67+
for part in path_parts:
68+
if not part:
69+
continue
70+
new_parts.append(part)
71+
if part[-1] not in path_separators:
72+
new_parts.append(path_sep)
73+
return ''.join(new_parts[:-1]) # Drop superfluous path separator.
7074

7175

7276
def _path_split(path):
@@ -1178,6 +1182,8 @@ def _setup(sys_module, _imp_module):
11781182

11791183
os_details = ('posix', ['/']), ('nt', ['\\', '/']), ('os2', ['\\', '/'])
11801184
for builtin_os, path_separators in os_details:
1185+
# Assumption made in _path_join()
1186+
assert all(len(sep) == 1 for sep in path_separators)
11811187
path_sep = path_separators[0]
11821188
if builtin_os in sys.modules:
11831189
os_module = sys.modules[builtin_os]

0 commit comments

Comments
 (0)