Skip to content

Commit 74abd98

Browse files
committed
bpo-39659: Route calls from pathlib.Path to os.getcwd() via the path accessor
1 parent 2219187 commit 74abd98

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):
@@ -469,6 +469,8 @@ def group(self, path):
469469
except ImportError:
470470
raise NotImplementedError("Path.group() is unsupported on this system")
471471

472+
getcwd = os.getcwd
473+
472474

473475
_normal_accessor = _NormalAccessor()
474476

@@ -1104,7 +1106,7 @@ def cwd(cls):
11041106
"""Return a new path pointing to the current working directory
11051107
(as returned by os.getcwd()).
11061108
"""
1107-
return cls(os.getcwd())
1109+
return cls(cls()._accessor.getcwd())
11081110

11091111
@classmethod
11101112
def home(cls):
@@ -1173,7 +1175,7 @@ def absolute(self):
11731175
return self
11741176
# FIXME this must defer to the specific flavour (and, under Windows,
11751177
# use nt._getfullpathname())
1176-
return self._from_parts([os.getcwd()] + self._parts)
1178+
return self._from_parts([self._accessor.getcwd()] + self._parts)
11771179

11781180
def resolve(self, strict=False):
11791181
"""

0 commit comments

Comments
 (0)