A context manager to temporarily change the current directory
(newdir: Union[str, Path])
| 54 | |
| 55 | @contextmanager |
| 56 | def cd(newdir: Union[str, Path]) -> Iterator[None]: |
| 57 | """ |
| 58 | A context manager to temporarily change the current directory |
| 59 | """ |
| 60 | prevdir = Path.cwd() |
| 61 | newdir = Path(newdir).expanduser() |
| 62 | os.chdir(newdir) |
| 63 | try: |
| 64 | yield |
| 65 | finally: |
| 66 | os.chdir(prevdir) |
| 67 | |
| 68 | |
| 69 | @overload |
no outgoing calls