def deactivate(self):
        """Restore the import state saved when this one activated."""
        if not self._saved:
            raise TypeError("Not activated yet")

        # sys.modules = self.modules
        sys.meta_path = self._saved.meta_path
        sys.path = self._saved.path
        sys.path_hooks = self._saved.path_hooks
        sys.path_importer_cache = self._saved.path_importer_cache

        # accommodate sys.module's quirkiness
        self.modules.clear()
        self.modules.update(sys.modules)
        sys.modules.clear()
        sys.modules.update(self._saved.modules)

        self._saved = None
Restore the import state saved when this one activated.
recipes/Python/578107_Tracking_Manipulating_PythImport/recipe-578107.py