From 81b8d193bca9fa38974ec8de647d5b8801c2d5e6 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 8 May 2023 23:42:55 -0700 Subject: [PATCH] Move `history_file` from global into `Coder` class. # Context: USER: move history_file from global into Coder ASSISTANT: To move the `history_file` variable from the global scope into the `Coder` class, you can add it as a class attribute and update its usage accordingly. ```python coder.py <<<<<<< ORIGINAL history_file = ".coder.history" try: readline.read_history_file(history_file) except FileNotFoundError: pass ======= class Coder: history_file = ".coder.history" def __init__(self, main_model, files, pretty): # ... try: readline.read_history_file(self.history_file) except FileNotFoundError: pass # ... >>>>>>> UPDATED ``` ```python coder.py <<<<<<< ORIGINAL readline.write_history_file(history_file) ======= readline.write_history_file(self.history_file) >>>>>>> UPDATED ``` --- coder.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/coder.py b/coder.py index 48904ae9e..7bedb15da 100755 --- a/coder.py +++ b/coder.py @@ -26,12 +26,16 @@ from dump import dump import prompts -history_file = ".coder.history" -try: - readline.read_history_file(history_file) -except FileNotFoundError: - pass +class Coder: + history_file = ".coder.history" + def __init__(self, main_model, files, pretty): + # ... + try: + readline.read_history_file(self.history_file) + except FileNotFoundError: + pass + # ... openai.api_key = os.getenv("OPENAI_API_KEY") @@ -164,7 +168,7 @@ class Coder: else: print() - readline.write_history_file(history_file) + readline.write_history_file(self.history_file) return inp def get_last_modified(self): @@ -630,4 +634,4 @@ def main(): if __name__ == "__main__": status = main() - sys.exit(status) + sys.exit(status) \ No newline at end of file