Skip to content

Commit b05440c

Browse files
authored
bpo-39659: Route calls from pathlib.Path to os.getcwd() via the path accessor (GH-18834)
1 parent 8aac1be commit b05440c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/pathlib.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def compile_pattern(self, pattern):
187187
def resolve(self, path, strict=False):
188188
s = str(path)
189189
if not s:
190-
return os.getcwd()
190+
return path._accessor.getcwd()
191191
previous_s = None
192192
if _getfinalpathname is not None:
193193
if strict:
@@ -352,7 +352,7 @@ def _resolve(path, rest):
352352
return path
353353
# NOTE: according to POSIX, getcwd() cannot contain path components
354354
# which are symlinks.
355-
base = '' if path.is_absolute() else os.getcwd()
355+
base = '' if path.is_absolute() else accessor.getcwd()
356356
return _resolve(base, str(path)) or sep
357357

358358
def is_reserved(self, parts):
@@ -461,6 +461,8 @@ def group(self, path):
461461
except ImportError:
462462
raise NotImplementedError("Path.group() is unsupported on this system")
463463

464+
getcwd = os.getcwd
465+
464466

465467
_normal_accessor = _NormalAccessor()
466468

@@ -1096,7 +1098,7 @@ def cwd(cls):
10961098
"""Return a new path pointing to the current working directory
10971099
(as returned by os.getcwd()).
10981100
"""
1099-
return cls(os.getcwd())
1101+
return cls(cls()._accessor.getcwd())
11001102

11011103
@classmethod
11021104
def home(cls):
@@ -1165,7 +1167,7 @@ def absolute(self):
11651167
return self
11661168
# FIXME this must defer to the specific flavour (and, under Windows,
11671169
# use nt._getfullpathname())
1168-
return self._from_parts([os.getcwd()] + self._parts)
1170+
return self._from_parts([self._accessor.getcwd()] + self._parts)
11691171

11701172
def resolve(self, strict=False):
11711173
"""

0 commit comments

Comments
 (0)