Skip to content

Commit

Permalink
pythongh-117636: Remove redundant type check in os.path.join() (pyt…
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo authored Apr 14, 2024
1 parent e018317 commit 9ee94d1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def join(path, *paths):
seps = '\\/'
colon_seps = ':\\/'
try:
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
result_drive, result_root, result_path = splitroot(path)
for p in paths:
p_drive, p_root, p_path = splitroot(p)
Expand Down
6 changes: 2 additions & 4 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ def join(a, *p):
sep = _get_sep(a)
path = a
try:
if not p:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
for b in p:
b = os.fspath(b)
if b.startswith(sep):
if b.startswith(sep) or not path:
path = b
elif not path or path.endswith(sep):
elif path.endswith(sep):
path += b
else:
path += sep + b
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_join(self):
self.assertEqual(fn(b"/foo", b"bar", b"baz"), b"/foo/bar/baz")
self.assertEqual(fn(b"/foo/", b"bar/", b"baz/"), b"/foo/bar/baz/")

self.assertEqual(fn("a", ""), "a/")
self.assertEqual(fn("a", "", ""), "a/")
self.assertEqual(fn("a", "b"), "a/b")
self.assertEqual(fn("a", "b/"), "a/b/")
self.assertEqual(fn("a/", "b"), "a/b")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speedup :func:`os.path.join`.

0 comments on commit 9ee94d1

Please sign in to comment.