summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2023-02-17 14:08:14 (GMT)
committerGitHub <noreply@github.com>2023-02-17 14:08:14 (GMT)
commit072011b3c38f871cdc3ab62630ea2234d09456d1 (patch)
tree5305bd780eb338a27ce67428077773bf0565a5f5 /Lib/pathlib.py
parentd401b20630965c0e1d2a5a0d60d5fc51aa5a8d80 (diff)
downloadcpython-072011b3c38f871cdc3ab62630ea2234d09456d1.zip
cpython-072011b3c38f871cdc3ab62630ea2234d09456d1.tar.gz
cpython-072011b3c38f871cdc3ab62630ea2234d09456d1.tar.bz2
gh-100809: Fix handling of drive-relative paths in pathlib.Path.absolute() (GH-100812)
Resolving the drive independently uses the OS API, which ensures it starts from the current directory on that drive.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index d7994a3..dde5735 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -816,7 +816,12 @@ class Path(PurePath):
"""
if self.is_absolute():
return self
- return self._from_parts([os.getcwd()] + self._parts)
+ elif self._drv:
+ # There is a CWD on each drive-letter drive.
+ cwd = self._flavour.abspath(self._drv)
+ else:
+ cwd = os.getcwd()
+ return self._from_parts([cwd] + self._parts)
def resolve(self, strict=False):
"""