Skip to content

Commit

Permalink
os.path: refactor: use sep instead of literal /
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hirsch <michael@scivision.dev>
  • Loading branch information
scivision committed Sep 14, 2023
1 parent e6b89ea commit 0c1524e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions python-stdlib/os-path/os/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ def normpath(s):


def abspath(s):
if s[0] != "/":
return os.getcwd() + "/" + s
if s[0] != sep:
return os.getcwd() + sep + s
return s


def join(*args):
# TODO: this is non-compliant
if type(args[0]) is bytes:
return b"/".join(args)
return bytes(sep).join(args)
else:
return "/".join(args)
return sep.join(args)


def split(path):
if path == "":
return ("", "")
r = path.rsplit("/", 1)
r = path.rsplit(sep, 1)
if len(r) == 1:
return ("", path)
head = r[0] # .rstrip("/")
if not head:
head = "/"
head = sep
return (head, r[1])


Expand Down Expand Up @@ -67,7 +67,7 @@ def isdir(path):


def expanduser(s):
if s == "~" or s.startswith("~/"):
if s == "~" or s.startswith("~" + sep):
h = os.getenv("HOME")
return h + s[1:]
if s[0] == "~":
Expand Down

0 comments on commit 0c1524e

Please sign in to comment.