AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
remove unused imports automatically (#4449)
merwanehamadiee9f10a8d813
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.mdindex 81a4b90aad..f159c646d6 100644--- a/.github/PULL_REQUEST_TEMPLATE.md+++ b/.github/PULL_REQUEST_TEMPLATE.md@@ -36,7 +36,13 @@ By following these guidelines, your PRs are more likely to be merged quickly aft- [ ] I have considered potential risks and mitigations for my changes.- [ ] I have documented my changes clearly and comprehensively.- [ ] I have not snuck in any "extra" small tweaks changes. <!-- Submit these as separate Pull Requests, they are the easiest to merge! -->-- [ ] I have run `black .` and `isort .` against my code to ensure it passes our linter.+- [ ] I have run the following commands against my code to ensure it passes our linters:+ ```shell+ black .+ isort .+ mypy+ autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests --in-place+ ```<!-- If you haven't added tests, please explain why. If you have, check the appropriate box. If you've ensured your PR is atomic and well-documented, check the corresponding boxes. -->diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex e91cb960c8..368930a15f 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -51,6 +51,11 @@ jobs:run: mypyif: success() || failure()+ - name: Check for unused imports and pass statements+ run: |+ cmd="autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests"+ $cmd --check || (echo "You have unused imports or pass statements, please run '${cmd} --in-place'" && exit 1)+test:permissions:# Gives the action the necessary permissions for publishing newdiff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 345d88be9a..5392860317 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -21,6 +21,7 @@ repos:hooks:- id: blacklanguage_version: python3.10+- repo: https://github.com/pre-commit/mirrors-mypyrev: 'v1.3.0'hooks:@@ -28,6 +29,11 @@ repos:- repo: localhooks:+ - id: autoflake+ name: autoflake+ entry: autoflake --in-place --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests+ language: python+ types: [ python ]- id: pytest-checkname: pytest-checkentry: pytest --cov=autogpt --without-integration --without-slow-integrationdiff --git a/autogpt/app.py b/autogpt/app.pyindex 985bf0f89e..0804b48271 100644--- a/autogpt/app.py+++ b/autogpt/app.py@@ -1,6 +1,6 @@""" Command and Control """import json-from typing import Dict, List, NoReturn, Union+from typing import Dict, List, Unionfrom autogpt.agent.agent_manager import AgentManagerfrom autogpt.commands.command import CommandRegistry, commanddiff --git a/autogpt/commands/command.py b/autogpt/commands/command.pyindex e99a68c08a..742cc8df64 100644--- a/autogpt/commands/command.py+++ b/autogpt/commands/command.py@@ -1,7 +1,7 @@import functoolsimport importlibimport inspect-from typing import TYPE_CHECKING, Any, Callable, Optional+from typing import Any, Callable, Optionalfrom autogpt.config import Configfrom autogpt.logs import loggerdiff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.pyindex e8ef65516c..20c5e1a27e 100644--- a/autogpt/commands/execute_code.py+++ b/autogpt/commands/execute_code.py@@ -2,7 +2,6 @@import osimport subprocessfrom pathlib import Path-from typing import TYPE_CHECKINGimport dockerfrom docker.errors import ImageNotFounddiff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.pyindex 8288e3898a..824db50c8b 100644--- a/autogpt/commands/file_operations.py+++ b/autogpt/commands/file_operations.py@@ -6,7 +6,6 @@ import osimport os.pathfrom typing import TYPE_CHECKING, Generator, Literal-import charset_normalizerimport requestsfrom colorama import Back, Forefrom requests.adapters import HTTPAdapter, Retrydiff --git a/autogpt/commands/web_selenium.py b/autogpt/commands/web_selenium.pyindex da6dd35dcc..3cc99282b0 100644--- a/autogpt/commands/web_selenium.py+++ b/autogpt/commands/web_selenium.py@@ -29,7 +29,7 @@ from webdriver_manager.microsoft import EdgeChromiumDriverManager as EdgeDriverMfrom autogpt.commands.command import commandfrom autogpt.logs import logger-from autogpt.memory.vector import MemoryItem, NoMemory, get_memory+from autogpt.memory.vector import MemoryItem, get_memoryfrom autogpt.processing.html import extract_hyperlinks, format_hyperlinksfrom autogpt.url_utils.validators import validate_urldiff --git a/autogpt/llm/base.py b/autogpt/llm/base.pyindex 5018b70376..76bd3db1c8 100644--- a/autogpt/llm/base.py+++ b/autogpt/llm/base.py@@ -44,15 +44,11 @@ class ModelInfo:class ChatModelInfo(ModelInfo):"""Struct for chat model information."""- pass-@dataclassclass TextModelInfo(ModelInfo):"""Struct for text completion model information."""- pass-@dataclassclass EmbeddingModelInfo(ModelInfo):diff --git a/autogpt/llm/chat.py b/autogpt/llm/chat.pyindex c55016f26c..292990f5f0 100644--- a/autogpt/llm/chat.py+++ b/autogpt/llm/chat.py@@ -1,7 +1,6 @@from __future__ import annotationsimport time-from random import shufflefrom typing import TYPE_CHECKINGif TYPE_CHECKING:@@ -13,7 +12,6 @@ from autogpt.llm.base import ChatSequence, Messagefrom autogpt.llm.utils import count_message_tokens, create_chat_completionfrom autogpt.log_cycle.log_cycle import CURRENT_CONTEXT_FILE_NAMEfrom autogpt.logs import logger-from autogpt.memory.vector import MemoryItem, get_memorycfg = Config()diff --git a/autogpt/memory/vector/utils.py b/autogpt/memory/vector/utils.pyindex d01f710848..75d1f69d4b 100644--- a/autogpt/memory/vector/utils.py+++ b/autogpt/memory/vector/utils.py@@ -1,7 +1,6 @@from typing import Any, overloadimport numpy as np-import numpy.typing as nptimport openaifrom autogpt.config import Configdiff --git a/autogpt/models/base_open_ai_plugin.py b/autogpt/models/base_open_ai_plugin.pyindex 8f6dd52c67..c0aac8ed2e 100644--- a/autogpt/models/base_open_ai_plugin.py+++ b/autogpt/models/base_open_ai_plugin.py@@ -68,7 +68,6 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):prompt (PromptGenerator): The prompt generator.messages (List[str]): The list of messages."""- passdef can_handle_post_planning(self) -> bool:"""This method is called to check that the plugin can@@ -116,7 +115,6 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):Returns:Optional[str]: The resulting message."""- passdef can_handle_post_instruction(self) -> bool:"""This method is called to check that the plugin can@@ -196,7 +194,6 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):Returns:str: The resulting response."""- passdef can_handle_text_embedding(self, text: str) -> bool:"""This method is called to check that the plugin can@@ -214,7 +211,6 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):Returns:list: The text embedding."""- passdef can_handle_user_input(self, user_input: str) -> bool:"""This method is called to check that the plugin can@@ -237,8 +233,6 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):str: The user input."""- pass-def can_handle_report(self) -> bool:"""This method is called to check that the plugin canhandle the report method.@@ -253,4 +247,3 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):Args:message (str): The message to report."""- passdiff --git a/autogpt/plugins.py b/autogpt/plugins.pyindex 780593a8df..f36ba36e0f 100644--- a/autogpt/plugins.py+++ b/autogpt/plugins.py@@ -5,7 +5,7 @@ import jsonimport osimport zipfilefrom pathlib import Path-from typing import List, Optional, Tuple+from typing import Listfrom urllib.parse import urlparsefrom zipimport import zipimporterdiff --git a/autogpt/singleton.py b/autogpt/singleton.pyindex 55b2aeea12..b3a5af529b 100644--- a/autogpt/singleton.py+++ b/autogpt/singleton.py@@ -20,5 +20,3 @@ class AbstractSingleton(abc.ABC, metaclass=Singleton):"""Abstract singleton class for ensuring only one instance of a class."""-- passdiff --git a/autogpt/speech/base.py b/autogpt/speech/base.pyindex 7adcc37d54..a7570d9456 100644--- a/autogpt/speech/base.py+++ b/autogpt/speech/base.py@@ -37,7 +37,6 @@ class VoiceBase(AbstractSingleton):"""Setup the voices, API key, etc."""- pass@abc.abstractmethoddef _speech(self, text: str, voice_index: int = 0) -> bool:@@ -47,4 +46,3 @@ class VoiceBase(AbstractSingleton):Args:text (str): The text to play."""- passdiff --git a/autogpt/speech/brian.py b/autogpt/speech/brian.pyindex ffa4e51e77..f63c206b22 100644--- a/autogpt/speech/brian.py+++ b/autogpt/speech/brian.py@@ -12,7 +12,6 @@ class BrianSpeech(VoiceBase):def _setup(self) -> None:"""Setup the voices, API key, etc."""- passdef _speech(self, text: str, _: int = 0) -> bool:"""Speak text using Brian with the streamelements APIdiff --git a/autogpt/utils.py b/autogpt/utils.pyindex 8eb95deb91..653841a232 100644--- a/autogpt/utils.py+++ b/autogpt/utils.py@@ -6,15 +6,8 @@ import yamlfrom colorama import Fore, Stylefrom git.repo import Repo-from autogpt.logs import logger--# Use readline if available (for clean_input)-try:- import readline-except ImportError:- pass-from autogpt.config import Config+from autogpt.logs import loggerdef batch(iterable, max_batch_length: int, overlap: int = 0):diff --git a/tests/integration/challenges/conftest.py b/tests/integration/challenges/conftest.pyindex 9bb5a1a4c6..c196fc727c 100644--- a/tests/integration/challenges/conftest.py+++ b/tests/integration/challenges/conftest.py@@ -2,7 +2,6 @@ import pytestfrom _pytest.config import Configfrom _pytest.config.argparsing import Parserfrom _pytest.fixtures import FixtureRequest-from _pytest.monkeypatch import MonkeyPatchdef pytest_addoption(parser: Parser) -> None:diff --git a/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.py b/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.pyindex 0a0c634ce8..1d33281763 100644--- a/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.py+++ b/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.py@@ -1,8 +1,6 @@-import typing-import pytest-from autogpt.commands.file_operations import read_file, write_to_file+from autogpt.commands.file_operations import read_filefrom autogpt.config import Configfrom tests.integration.challenges.utils import run_interaction_loopfrom tests.utils import requires_api_keydiff --git a/tests/integration/challenges/utils.py b/tests/integration/challenges/utils.pyindex b7bf83fed2..94dd5a0ce9 100644--- a/tests/integration/challenges/utils.py+++ b/tests/integration/challenges/utils.py@@ -1,7 +1,7 @@import contextlibimport randomfrom functools import wraps-from typing import Any, Callable, Dict, Generator, Optional, Tuple+from typing import Any, Callable, Dict, Generator, Tupleimport pytestdiff --git a/tests/integration/memory/conftest.py b/tests/integration/memory/conftest.pyindex f7fe295af4..64ac651dee 100644--- a/tests/integration/memory/conftest.py+++ b/tests/integration/memory/conftest.py@@ -1,4 +1,3 @@-import numpyimport pytestfrom autogpt.memory.vector.memory_item import MemoryItemdiff --git a/tests/integration/test_setup.py b/tests/integration/test_setup.pyindex 444d94747f..4e2a505d9a 100644--- a/tests/integration/test_setup.py+++ b/tests/integration/test_setup.py@@ -3,11 +3,7 @@ from unittest.mock import patchimport pytestfrom autogpt.config.ai_config import AIConfig-from autogpt.setup import (- generate_aiconfig_automatic,- generate_aiconfig_manual,- prompt_user,-)+from autogpt.setup import generate_aiconfig_automatic, prompt_userfrom tests.utils import requires_api_keydiff --git a/tests/test_audio_text_read_audio.py b/tests/test_audio_text_read_audio.pyindex 1f324601cb..4385da321c 100644--- a/tests/test_audio_text_read_audio.py+++ b/tests/test_audio_text_read_audio.py@@ -1,7 +1,6 @@# Date: 2023-5-13# Author: Generated by GoCodeo.import json-from io import BytesIOfrom unittest.mock import MagicMock, patchimport pytestdiff --git a/tests/test_config.py b/tests/test_config.pyindex 1e156f98d9..81d151cd24 100644--- a/tests/test_config.py+++ b/tests/test_config.py@@ -5,7 +5,6 @@ for the AI and ensures it behaves as a singleton.from unittest.mock import patchimport pytest-from openai import InvalidRequestErrorfrom autogpt.configurator import create_configdiff --git a/tests/test_image_gen.py b/tests/test_image_gen.pyindex 59962af0ee..5c04921b5a 100644--- a/tests/test_image_gen.py+++ b/tests/test_image_gen.py@@ -7,7 +7,6 @@ import pytestfrom PIL import Imagefrom autogpt.commands.image_gen import generate_image, generate_image_with_sd_webui-from autogpt.config import Configfrom tests.utils import requires_api_keydiff --git a/tests/test_text_file_parsers.py b/tests/test_text_file_parsers.pyindex d15c63ae95..2e71aa69f9 100644--- a/tests/test_text_file_parsers.py+++ b/tests/test_text_file_parsers.py@@ -1,13 +1,11 @@import jsonimport tempfile-from functools import partialfrom unittest import TestCasefrom xml.etree import ElementTreeimport docximport yamlfrom bs4 import BeautifulSoup-from PyPDF2 import PdfWriterfrom autogpt.commands.file_operations_utils import is_file_binary_fn, read_textual_filefrom autogpt.logs import loggerdiff --git a/tests/test_utils.py b/tests/test_utils.pyindex f9ab36987e..c0ce28cc1f 100644--- a/tests/test_utils.py+++ b/tests/test_utils.py@@ -1,13 +1,10 @@import os-from unittest.mock import Mock, patch+from unittest.mock import patchimport pytestimport requests-from colorama import Fore-from git import Repofrom autogpt.utils import (- clean_input,get_bulletin_from_web,get_current_git_branch,get_latest_bulletin,diff --git a/tests/unit/models/test_base_open_api_plugin.py b/tests/unit/models/test_base_open_api_plugin.pyindex 456c74c762..4d41eddd37 100644--- a/tests/unit/models/test_base_open_api_plugin.py+++ b/tests/unit/models/test_base_open_api_plugin.py@@ -1,19 +1,11 @@-from typing import Any, Dict, List, Optional, Tuple-import pytest-from autogpt.models.base_open_ai_plugin import (- BaseOpenAIPlugin,- Message,- PromptGenerator,-)+from autogpt.models.base_open_ai_plugin import BaseOpenAIPluginclass DummyPlugin(BaseOpenAIPlugin):"""A dummy plugin for testing purposes."""- pass-@pytest.fixturedef dummy_plugin():diff --git a/tests/unit/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.pyindex 15f495dbbb..2d1e8f9032 100644--- a/tests/unit/test_browse_scrape_links.py+++ b/tests/unit/test_browse_scrape_links.py@@ -2,7 +2,6 @@# Dependencies:# pip install pytest-mock-import pytestfrom autogpt.commands.web_requests import scrape_linksdiff --git a/tests/unit/test_json_parser.py b/tests/unit/test_json_parser.pyindex 69cddca6c6..be5f07339f 100644--- a/tests/unit/test_json_parser.py+++ b/tests/unit/test_json_parser.py@@ -1,7 +1,6 @@from unittest import TestCasefrom autogpt.json_utils.json_fix_llm import fix_and_parse_json-from tests.utils import skip_in_ciclass TestParseJson(TestCase):diff --git a/tests/unit/test_json_utils_llm.py b/tests/unit/test_json_utils_llm.pyindex b8c9518de5..93e01acb92 100644--- a/tests/unit/test_json_utils_llm.py+++ b/tests/unit/test_json_utils_llm.py@@ -1,12 +1,9 @@# Generated by CodiumAI-import pytest-from loguru import loggerfrom autogpt.json_utils.json_fix_llm import (fix_and_parse_json,fix_json_using_multiple_techniques,)-from tests.utils import requires_api_key"""Code Analysisdiff --git a/tests/unit/test_plugins.py b/tests/unit/test_plugins.pyindex 885ec4c331..6aa8dd47ca 100644--- a/tests/unit/test_plugins.py+++ b/tests/unit/test_plugins.py@@ -1,6 +1,5 @@import pytest-from autogpt.config import Configfrom autogpt.plugins import denylist_allowlist_check, inspect_zip_for_modulesPLUGINS_TEST_DIR = "tests/unit/data/test_plugins"diff --git a/tests/vcr/vcr_filter.py b/tests/vcr/vcr_filter.pyindex a86f501a96..4cc49fd301 100644--- a/tests/vcr/vcr_filter.py+++ b/tests/vcr/vcr_filter.py@@ -1,5 +1,4 @@import json-import osimport refrom typing import Any, Dict, List