Skip to content

Commit 9ee94d1

Browse files
authored
gh-117636: Remove redundant type check in os.path.join() (#117638)
1 parent e018317 commit 9ee94d1

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

Lib/ntpath.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ def join(path, *paths):
108108
seps = '\\/'
109109
colon_seps = ':\\/'
110110
try:
111-
if not paths:
112-
path[:0] + sep #23780: Ensure compatible data type even if p is null.
113111
result_drive, result_root, result_path = splitroot(path)
114112
for p in paths:
115113
p_drive, p_root, p_path = splitroot(p)

Lib/posixpath.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ def join(a, *p):
7777
sep = _get_sep(a)
7878
path = a
7979
try:
80-
if not p:
81-
path[:0] + sep #23780: Ensure compatible data type even if p is null.
8280
for b in p:
8381
b = os.fspath(b)
84-
if b.startswith(sep):
82+
if b.startswith(sep) or not path:
8583
path = b
86-
elif not path or path.endswith(sep):
84+
elif path.endswith(sep):
8785
path += b
8886
else:
8987
path += sep + b

Lib/test/test_posixpath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def test_join(self):
5656
self.assertEqual(fn(b"/foo", b"bar", b"baz"), b"/foo/bar/baz")
5757
self.assertEqual(fn(b"/foo/", b"bar/", b"baz/"), b"/foo/bar/baz/")
5858

59+
self.assertEqual(fn("a", ""), "a/")
60+
self.assertEqual(fn("a", "", ""), "a/")
5961
self.assertEqual(fn("a", "b"), "a/b")
6062
self.assertEqual(fn("a", "b/"), "a/b/")
6163
self.assertEqual(fn("a/", "b"), "a/b")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speedup :func:`os.path.join`.

0 commit comments

Comments
 (0)