mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
Merge 9f4ee6faa6 into a273bc99d2
This commit is contained in:
commit
696674fe2a
2 changed files with 8 additions and 1 deletions
|
|
@ -807,7 +807,12 @@ class chdir(AbstractContextManager):
|
|||
self._old_cwd = []
|
||||
|
||||
def __enter__(self):
|
||||
self._old_cwd.append(os.getcwd())
|
||||
# try to chdir to the current cwd so that we preemptively fail if we are
|
||||
# unnable to chdir back to it, see bpo-45545
|
||||
old_cwd = os.getcwd()
|
||||
os.chdir(old_cwd)
|
||||
|
||||
self._old_cwd.append(old_cwd)
|
||||
os.chdir(self.path)
|
||||
|
||||
def __exit__(self, *excinfo):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Premptively fail in :func:`contextdir.chdir` if we can't change back to the
|
||||
original directory.
|
||||
Loading…
Add table
Add a link
Reference in a new issue