diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000000..e2ad79c0281 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,44 @@ +--- +name: Linting + +on: + push: + paths-ignore: + - 'aider/website/**' + - README.md + - HISTORY.md + branches: + - main + pull_request: + paths-ignore: + - 'aider/website/**' + - README.md + branches: + - main + +jobs: + mypy: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install mypy + pip install '.[dev]' + + - name: Run Mypy + uses: wearerequired/lint-action@v2.3.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + mypy: true + mypy_args: "." + continue_on_error: false diff --git a/aider/coders/__init__.py b/aider/coders/__init__.py index e9d334bc99f..b87c395ccaa 100644 --- a/aider/coders/__init__.py +++ b/aider/coders/__init__.py @@ -12,15 +12,15 @@ # from .single_wholefile_func_coder import SingleWholeFileFunctionCoder __all__ = [ - HelpCoder, - AskCoder, - Coder, - EditBlockCoder, - EditBlockFencedCoder, - WholeFileCoder, - UnifiedDiffCoder, - # SingleWholeFileFunctionCoder, - ArchitectCoder, - EditorEditBlockCoder, - EditorWholeFileCoder, + "HelpCoder", + "AskCoder", + "Coder", + "EditBlockCoder", + "EditBlockFencedCoder", + "WholeFileCoder", + "UnifiedDiffCoder", + # "SingleWholeFileFunctionCoder", + "ArchitectCoder", + "EditorEditBlockCoder", + "EditorWholeFileCoder", ] diff --git a/aider/coders/base_prompts.py b/aider/coders/base_prompts.py index c431c752018..447613e4156 100644 --- a/aider/coders/base_prompts.py +++ b/aider/coders/base_prompts.py @@ -1,3 +1,6 @@ +from __future__ import annotations + + class CoderPrompts: system_reminder = "" @@ -37,7 +40,7 @@ class CoderPrompts: " stop and wait for your approval." ) - repo_content_prefix = """Here are summaries of some files present in my git repository. + repo_content_prefix: str | None = """Here are summaries of some files present in my git repository. Do not propose changes to these files, treat them as *read-only*. If you need to edit any of these files, ask me to *add them to the chat* first. """ diff --git a/aider/io.py b/aider/io.py index 81829a83bdf..c933622a65e 100644 --- a/aider/io.py +++ b/aider/io.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import base64 import os from collections import defaultdict @@ -28,7 +30,7 @@ @dataclass class ConfirmGroup: - preference: str = None + preference: str | None = None show_group: bool = True def __init__(self, items=None): diff --git a/aider/llm.py b/aider/llm.py index f750f41af4c..ead446225ab 100644 --- a/aider/llm.py +++ b/aider/llm.py @@ -37,4 +37,4 @@ def _load_litellm(self): litellm = LazyLiteLLM() -__all__ = [litellm] +__all__ = ["litellm"] diff --git a/aider/models.py b/aider/models.py index 4e7e529d3f0..b340f99f850 100644 --- a/aider/models.py +++ b/aider/models.py @@ -20,7 +20,7 @@ DEFAULT_MODEL_NAME = "gpt-4o" ANTHROPIC_BETA_HEADER = "prompt-caching-2024-07-31" -OPENAI_MODELS = """ +_OPENAI_MODELS = """ gpt-4 gpt-4o gpt-4o-2024-05-13 @@ -47,9 +47,9 @@ gpt-3.5-turbo-16k-0613 """ -OPENAI_MODELS = [ln.strip() for ln in OPENAI_MODELS.splitlines() if ln.strip()] +OPENAI_MODELS = [ln.strip() for ln in _OPENAI_MODELS.splitlines() if ln.strip()] -ANTHROPIC_MODELS = """ +_ANTHROPIC_MODELS = """ claude-2 claude-2.1 claude-3-haiku-20240307 @@ -58,7 +58,7 @@ claude-3-5-sonnet-20240620 """ -ANTHROPIC_MODELS = [ln.strip() for ln in ANTHROPIC_MODELS.splitlines() if ln.strip()] +ANTHROPIC_MODELS = [ln.strip() for ln in _ANTHROPIC_MODELS.splitlines() if ln.strip()] @dataclass diff --git a/aider/repomap.py b/aider/repomap.py index f0d42e19624..ca08dd500fe 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -24,7 +24,7 @@ warnings.simplefilter("ignore", category=FutureWarning) from tree_sitter_languages import get_language, get_parser # noqa: E402 -Tag = namedtuple("Tag", "rel_fname fname line name kind".split()) +Tag = namedtuple("Tag", ("rel_fname", "fname", "line", "name", "kind")) SQLITE_ERRORS = (sqlite3.OperationalError, sqlite3.DatabaseError) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000000..cae65825f5d --- /dev/null +++ b/mypy.ini @@ -0,0 +1,40 @@ +[mypy] +exclude = (?x)( + ^\.git/ + | ^benchmark/$ + | ^build/$ + | ^dist/$ + | ^scripts/$ + ) +allow_untyped_globals = True +check_untyped_defs = False + +[mypy-configargparse] +ignore_missing_imports = True + +[mypy-diff_match_patch] +ignore_missing_imports = True + +[mypy-diskcache] +ignore_missing_imports = True + +[mypy-grep_ast.*] +ignore_missing_imports = True + +[mypy-imgcat] +ignore_missing_imports = True + +[mypy-llama_index.*] +ignore_missing_imports = True + +[mypy-pypandoc] +ignore_missing_imports = True + +[mypy-pyperclip] +ignore_missing_imports = True + +[mypy-soundfile] +ignore_missing_imports = True + +[mypy-sounddevice] +ignore_missing_imports = True