Skip to content

Commit bcc160e

Browse files
nineteendoeryksun
andauthored
Update Lib/ntpath.py
Co-authored-by: Eryk Sun <[email protected]>
1 parent 68bb224 commit bcc160e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Lib/ntpath.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,21 +580,21 @@ def abspath(path):
580580
pass
581581
path = os.fspath(path)
582582
if not isabs(path):
583-
if isinstance(path, bytes):
583+
if is_bytes := isinstance(path, bytes):
584584
sep = b'\\'
585-
cwd = os.getcwdb()
586585
else:
587586
sep = '\\'
588-
cwd = os.getcwd()
589587
drive, root, path = splitroot(path)
590-
if drive and drive != splitroot(cwd)[0]:
588+
# Either drive or root can be nonempty, but not both.
589+
if drive or root:
591590
try:
592-
path = join(_getfullpathname(drive), path)
591+
path = join(_getfullpathname(drive + root), path)
593592
except (OSError, ValueError):
594-
# Invalid drive \x00: on Windows; assume root directory
593+
# Drive "\0:" cannot exist; use the root directory.
595594
path = drive + sep + path
596595
else:
597-
path = join(cwd, root + path)
596+
cwd = os.getcwdb() if is_bytes else os.getcwd()
597+
path = join(cwd, path)
598598
return normpath(path)
599599

600600
try:

0 commit comments

Comments
 (0)