Context manager for changing dir and restoring previous workdir after exit.

def chdir(path: str) -> Iterator[None]:
    """Context manager for changing dir and restoring previous workdir after exit.
    """
    curdir = os.getcwd()
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(curdir)