From d97bf17e19d73e0c62e894a60468cf182b2c7531 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 5 Jul 2023 21:30:57 -0700 Subject: [PATCH] aider: Moved the import statement for the `glob` module to the top of the `aider/commands.py` file. # Context: USER: I ran this command: pytest tests/test_commands.py And got this output: ============================= test session starts ============================== platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.2.0 rootdir: /Users/gauthier/Projects/aider configfile: pytest.ini collected 1 item tests/test_commands.py F [100%] =================================== FAILURES =================================== _________________ TestCommands.test_cmd_add_with_glob_patterns _________________ self = def test_cmd_add_with_glob_patterns(self): # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True) from aider.coders import Coder coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef") commands = Commands(io, coder) # Create some test files with open("test1.py", "w") as f: f.write("print('test1')") with open("test2.py", "w") as f: f.write("print('test2')") with open("test.txt", "w") as f: f.write("test") # Call the cmd_add method with a glob pattern > commands.cmd_add("*.py") tests/test_commands.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , args = '*.py' def cmd_add(self, args): "Add matching files to the chat session using glob patterns" added_fnames = [] for pattern in args.split(): > matched_files = glob.glob(pattern, recursive=True) E NameError: name 'glob' is not defined aider/commands.py:226: NameError ----------------------------- Captured stdout call ----------------------------- Model: gpt-3.5-turbo Git repo: none Repo-map: disabled =========================== short test summary info ============================ FAILED tests/test_commands.py::TestCommands::test_cmd_add_with_glob_patterns ============================== 1 failed in 0.92s =============================== ASSISTANT: The error message indicates that the `glob` module is not defined in the `cmd_add` method of the `Commands` class in the `aider/commands.py` file. This is because the `glob` module is imported inside the `Commands` class, but it should be imported at the top of the file. Here are the changes you need to make: ```python aider/commands.py <<<<<<< ORIGINAL import json import os import shlex import subprocess import sys import git import tiktoken from prompt_toolkit.completion import Completion from aider import prompts, utils class Commands: import glob ======= import json import os import shlex import subprocess import sys import glob import git import tiktoken from prompt_toolkit.completion import Completion from aider import prompts, utils class Commands: >>>>>>> UPDATED ``` This change moves the `import glob` statement from inside the `Commands` class to the top of the file, which is the standard place for import statements in Python. This will make the `glob` module available to all methods in the `Commands` class. --- aider/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index b053cba4e..d5b1f2eb9 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -3,6 +3,7 @@ import os import shlex import subprocess import sys +import glob import git import tiktoken @@ -10,7 +11,6 @@ from prompt_toolkit.completion import Completion from aider import prompts, utils - class Commands: def __init__(self, io, coder): self.io = io