Skip to content

Commit

Permalink
Fix WindowsPath('/').absolute()
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 4, 2023
1 parent b827144 commit ca7119e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,10 +1416,8 @@ def absolute(self):
if self.is_absolute():
return self
elif self.root:
cwd = os.getcwd()
if self._tail:
cwd_drv = os.path.splitroot(cwd)[0]
return self._from_parsed_parts(cwd_drv, self.root, self._tail)
cwd_drv = os.path.splitroot(os.getcwd())[0]
return self._from_parsed_parts(cwd_drv, self.root, self._tail)
else:
cwd = os.path.abspath(self.drive) if self.drive else os.getcwd()
if self._tail:
Expand All @@ -1432,11 +1430,12 @@ def absolute(self):
else:
cwd_tail = self._tail
return self._from_parsed_parts(cwd_drv, cwd_root, cwd_tail)
# Optimization: store the result of os.getcwd() as the normalized
# string representation of the path.
result = self.with_segments(cwd)
result._str = cwd
return result
else:
# Optimization: store the result of os.getcwd() as the normalized
# string representation of the path.
result = self.with_segments(cwd)
result._str = cwd
return result

def resolve(self, strict=False):
"""
Expand Down

0 comments on commit ca7119e

Please sign in to comment.