From 8dfa56ad6aa9bac5f28da65bbe2ab4667f039863 Mon Sep 17 00:00:00 2001
From: Jerry Liu <jerryjliu98@gmail.com>
Date: Tue, 22 Nov 2022 22:02:34 -0800
Subject: [PATCH] abstract save function to base index class (#39)

---
 gpt_index/indices/base.py                   | 4 +++-
 gpt_index/indices/keyword_table/__init__.py | 1 +
 gpt_index/indices/list/__init__.py          | 1 +
 gpt_index/indices/list/base.py              | 5 -----
 gpt_index/indices/tree/__init__.py          | 1 +
 gpt_index/indices/tree/base.py              | 5 -----
 pyproject.toml                              | 2 +-
 7 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/gpt_index/indices/base.py b/gpt_index/indices/base.py
index 61a7bfecd8..e66eee6f68 100644
--- a/gpt_index/indices/base.py
+++ b/gpt_index/indices/base.py
@@ -1,4 +1,5 @@
 """Base data structure classes."""
+import json
 from abc import abstractmethod
 from typing import Any, Generic, List, Optional, TypeVar, cast
 
@@ -92,6 +93,7 @@ class BaseGPTIndex(Generic[IS]):
     def load_from_disk(cls, save_path: str, **kwargs: Any) -> "BaseGPTIndex":
         """Load from disk."""
 
-    @abstractmethod
     def save_to_disk(self, save_path: str) -> None:
         """Safe to file."""
+        with open(save_path, "w") as f:
+            json.dump(self.index_struct.to_dict(), f)
diff --git a/gpt_index/indices/keyword_table/__init__.py b/gpt_index/indices/keyword_table/__init__.py
index e69de29bb2..1d4640565a 100644
--- a/gpt_index/indices/keyword_table/__init__.py
+++ b/gpt_index/indices/keyword_table/__init__.py
@@ -0,0 +1 @@
+"""Init file."""
diff --git a/gpt_index/indices/list/__init__.py b/gpt_index/indices/list/__init__.py
index e69de29bb2..1d4640565a 100644
--- a/gpt_index/indices/list/__init__.py
+++ b/gpt_index/indices/list/__init__.py
@@ -0,0 +1 @@
+"""Init file."""
diff --git a/gpt_index/indices/list/base.py b/gpt_index/indices/list/base.py
index 1f763cf1f6..a8c09056ad 100644
--- a/gpt_index/indices/list/base.py
+++ b/gpt_index/indices/list/base.py
@@ -72,8 +72,3 @@ class GPTListIndex(BaseGPTIndex[IndexList]):
         """Load from disk."""
         with open(save_path, "r") as f:
             return cls(index_struct=IndexList.from_dict(json.load(f)), **kwargs)
-
-    def save_to_disk(self, save_path: str) -> None:
-        """Safe to file."""
-        with open(save_path, "w") as f:
-            json.dump(self.index_struct.to_dict(), f)
diff --git a/gpt_index/indices/tree/__init__.py b/gpt_index/indices/tree/__init__.py
index e69de29bb2..1d4640565a 100644
--- a/gpt_index/indices/tree/__init__.py
+++ b/gpt_index/indices/tree/__init__.py
@@ -0,0 +1 @@
+"""Init file."""
diff --git a/gpt_index/indices/tree/base.py b/gpt_index/indices/tree/base.py
index a94d82d5e2..0bd36731d6 100644
--- a/gpt_index/indices/tree/base.py
+++ b/gpt_index/indices/tree/base.py
@@ -136,8 +136,3 @@ class GPTTreeIndex(BaseGPTIndex[IndexGraph]):
         """Load from disk."""
         with open(save_path, "r") as f:
             return cls(index_struct=IndexGraph.from_dict(json.load(f)), **kwargs)
-
-    def save_to_disk(self, save_path: str) -> None:
-        """Safe to file."""
-        with open(save_path, "w") as f:
-            json.dump(self.index_struct.to_dict(), f)
diff --git a/pyproject.toml b/pyproject.toml
index 619e1edb28..b545d6ada3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,4 +4,4 @@ profile = "black"
 [tool.mypy]
 ignore_missing_imports = "True"
 disallow_untyped_defs = "True"
-exclude = ["notebooks"]
\ No newline at end of file
+exclude = ["notebooks", "build"]
\ No newline at end of file
-- 
GitLab