Skip to content

Commit

Permalink
add mypy (#684)
Browse files Browse the repository at this point in the history
Co-authored-by: daniel.eades <[email protected]>
  • Loading branch information
danieleades and daniel.eades authored Jan 5, 2024
1 parent c204fad commit 1cad8b3
Show file tree
Hide file tree
Showing 13 changed files with 626 additions and 381 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ jobs:

lint:
runs-on: ubuntu-latest
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: ruff
command: ruff check --output-format=github .
deps: --only lint-ruff
- name: mypy
command: mypy
deps: --with lint-typing
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.11"
- uses: snok/install-poetry@v1
- name: Install dependencies
run: poetry install --only lint
- name: Run Ruff
run: poetry run ruff check --output-format=github .
run: poetry install ${{ matrix.deps }}
- run: poetry run ${{ matrix.command }}

# test:
# runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions server/continuedev/core/autopilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def policy(self) -> Policy:

@property
def sdk(self) -> ContinueSDK:
return ContinueSDK(self.config, self.ide, self.gui, self, self.models) # type: ignore because of circular import
return ContinueSDK(self.config, self.ide, self.gui, self, self.models)

class Config:
arbitrary_types_allowed = True
Expand Down Expand Up @@ -218,11 +218,11 @@ def handle_step_update(
# Try to run step and handle errors
try:
if inspect.iscoroutinefunction(step.run):
await step.run(self.sdk) # type: ignore (stub type)
await step.run(self.sdk)
elif inspect.isasyncgenfunction(step.run):
async for update in step.run(self.sdk): # type: ignore (stub type)
async for update in step.run(self.sdk):
if self.stopped:
if on_stop_generator := step.on_stop(self.sdk): # type: ignore (stub type)
if on_stop_generator := step.on_stop(self.sdk):
for update in on_stop_generator: # type: ignore
if handled := handle_step_update(update):
yield handled
Expand Down Expand Up @@ -327,7 +327,7 @@ async def add_log(log: str):

if step is not None:
await self.run_step(step)
while next_step := self.policy.next(self.sdk.config, self.session_state): # type: ignore (stub type)
while next_step := self.policy.next(self.sdk.config, self.session_state):
await self.run_step(next_step)

self.sdk.models.remove_logger(logger_id)
Expand Down
4 changes: 2 additions & 2 deletions server/continuedev/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class ContextProvider(BaseModel):
)
ide: Any = None

delete_documents: Callable[[List[str]], Awaitable] = Field(
delete_documents: Callable[[List[str]], Awaitable] | None = Field(
None, description="Function to delete documents"
)
update_documents: Callable[[List[ContextItem], str], Awaitable] = Field(
update_documents: Callable[[List[ContextItem], str], Awaitable] | None = Field(
None, description="Function to update documents"
)

Expand Down
3 changes: 2 additions & 1 deletion server/continuedev/core/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ChatMessage,
ContextItem,
ContinueCustomException,
DeltaStep,

Check failure on line 27 in server/continuedev/core/steps.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

continuedev/core/steps.py:27:5: F401 `.main.DeltaStep` imported but unused
SessionUpdate,

Check failure on line 28 in server/continuedev/core/steps.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

continuedev/core/steps.py:28:5: F401 `.main.SessionUpdate` imported but unused
SetStep,
Step,
Expand Down Expand Up @@ -603,7 +604,7 @@ async def handle_generated_line(line: str):

params: Dict[str, Any] = {"prompt": rendered}
if template.__class__.__name__ == "PromptTemplate":
params.update(template.dict(exclude={"prompt"})) # type: ignore
params.update(template.dict(exclude={"prompt"}))

params.update(
{"max_tokens": min(max_tokens, model_to_use.context_length // 2, 4096)}
Expand Down
3 changes: 2 additions & 1 deletion server/continuedev/libs/index/pipelines/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ..hyde import code_hyde
from ..indices.chroma_index import ChromaCodebaseIndex
from ..indices.meilisearch_index import MeilisearchCodebaseIndex
from ..rerankers.default import default_reranker_parallel

Check failure on line 8 in server/continuedev/libs/index/pipelines/main.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

continuedev/libs/index/pipelines/main.py:8:33: F401 `..rerankers.default.default_reranker_parallel` imported but unused
from ..rerankers.single_token import single_token_reranker_parallel


Expand Down Expand Up @@ -58,7 +59,7 @@ async def main_retrieval_pipeline(
)
# Rerank to select top results
if use_reranking:
print("Selecting most important files...")
print(f"Selecting most important files...")

Check failure on line 62 in server/continuedev/libs/index/pipelines/main.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

continuedev/libs/index/pipelines/main.py:62:15: F541 f-string without any placeholders
chunks = await single_token_reranker_parallel(
chunks,
query,
Expand Down
2 changes: 0 additions & 2 deletions server/continuedev/libs/util/copy_codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from pathlib import Path
from typing import Iterable, List, Union

from continuedev.libs.util.calculate_diff import calculate_diff

from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer

Expand Down
2 changes: 1 addition & 1 deletion server/continuedev/libs/util/count_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def encoding_for_model(model_name: str):

try:
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
tiktoken_cache = os.path.join(sys._MEIPASS, "tiktoken_cache") # type: ignore
tiktoken_cache = os.path.join(sys._MEIPASS, "tiktoken_cache")
if os.path.exists(tiktoken_cache):
os.environ["TIKTOKEN_CACHE_DIR"] = tiktoken_cache

Expand Down
2 changes: 1 addition & 1 deletion server/continuedev/plugins/recipes/TemplateRecipe/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Coroutine

from ....core.main import Step
from ....core.main import Observation, Step

Check failure on line 3 in server/continuedev/plugins/recipes/TemplateRecipe/main.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

continuedev/plugins/recipes/TemplateRecipe/main.py:3:27: F401 `....core.main.Observation` imported but unused
from ....core.sdk import ContinueSDK, Models


Expand Down
2 changes: 1 addition & 1 deletion server/continuedev/plugins/steps/codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from typing import List, Optional, Union

from ...core.config import RetrievalSettings
from ...core.config import ModelDescription, RetrievalSettings
from ...core.main import (
ContextItem,
ContextItemDescription,
Expand Down
2 changes: 2 additions & 0 deletions server/continuedev/plugins/steps/steps_on_startup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Type

from ...core.main import Step
from ...core.sdk import ContinueSDK, Models

Expand Down
2 changes: 1 addition & 1 deletion server/continuedev/server/protocols/cli_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class CommandLineGUI(AbstractGUIProtocolServer):
async def send_session_update(self, session_update: SessionUpdate):
if hasattr(session_update.update, "description"):
print(session_update.update.description) # type: ignore
print(session_update.update.description)

async def send_indexing_progress(self, progress: float):
print(f"Indexing... {int(progress*100)}%")
Expand Down
Loading

0 comments on commit 1cad8b3

Please sign in to comment.