code: def preserve_cwd(func: Callable) -> Callable:
      
      # http://stackoverflow.com/questions/169070/python-how-do-i-write-a-decorator-that-restores-the-cwd  # noqa
      def decorator(*args_, **kwargs) -> Any:
          cwd = os.getcwd()
          result = func(*args_, **kwargs)
          os.chdir(cwd)
          return result
      return decorator
docs: Decorator to preserve the current working directory in calls to the
      decorated function.
  
      Example:
  
      .. code-block:: python
  
          @preserve_cwd
          def myfunc():
              os.chdir("/faraway")
  
          os.chdir("/home")
          myfunc()
          assert os.getcwd() == "/home"