Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codebase_rag/check_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

from collections.abc import Sequence
from pathlib import Path
from typing import Protocol, cast
from typing import Protocol

from . import constants as cs
from . import cypher_queries as cq
Expand Down Expand Up @@ -138,7 +138,7 @@ def _props(raw: object) -> PropertyDict | None:
scalars), but it is the graph's own property set read back, so it is
written back as it was read.
"""
return cast(PropertyDict, dict(raw)) if isinstance(raw, dict) else None
return dict(raw) if isinstance(raw, dict) else None


def _discard_pending(store: GraphStore) -> None:
Expand Down
10 changes: 5 additions & 5 deletions codebase_rag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import tempfile
import time
from collections.abc import Callable, Coroutine, Iterable, Iterator
from collections.abc import Callable, Coroutine, Generator, Iterable
from contextlib import ExitStack, contextmanager
from fnmatch import fnmatch
from functools import partial, wraps
Expand Down Expand Up @@ -574,7 +574,7 @@ def _start_active_projects(


@contextmanager
def _console_on_stderr() -> Iterator[None]:
def _console_on_stderr() -> Generator[None]:
console = app_context.console
app_context.console = terminal_aware_console(stderr=True)
try:
Expand Down Expand Up @@ -946,7 +946,7 @@ def _release_project_claim(batch_size: int, project_name: str, repo: Path) -> No
@contextmanager
def _project_claim(
batch_size: int, project_name: str, repo: Path, *, clean: bool, assume_yes: bool
) -> Iterator[list[str] | None]:
) -> Generator[list[str] | None]:
"""Hold this sync's claim on its project name while the sync runs (#2411).

Yields the roots `_mark_sync_incomplete` must still find on the Project.
Expand Down Expand Up @@ -984,7 +984,7 @@ def _mark_sync_incomplete(


@contextmanager
def _sync_lock_or_exit(repo: Path, project_name: str) -> Iterator[None]:
def _sync_lock_or_exit(repo: Path, project_name: str) -> Generator[None]:
"""Hold the checkout's sync lock for the whole sync, or stop first (#2441).

Taken before the `--clean` wipe and the `:IncompleteRun` marker, so a
Expand Down Expand Up @@ -2257,7 +2257,7 @@ def check_command(
@contextmanager
def _guarded_edit_reingest(
ingestor: MemgraphIngestor, updater: "GraphUpdater", project_name: str, repo: Path
) -> Iterator[tuple[EditReingest, "WriteMarker"]]:
) -> Generator[tuple[EditReingest, "WriteMarker"]]:
"""The re-ingest an applied edit is measured through, behind the marker.

Refuses before anything is planned when a run left the project's graph
Expand Down
6 changes: 3 additions & 3 deletions codebase_rag/editing/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import shutil
import tempfile
import uuid
from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator, Iterator
from contextlib import contextmanager, nullcontext
from datetime import UTC, datetime
from pathlib import Path
Expand Down Expand Up @@ -82,7 +82,7 @@ class TransactionError(ValueError):


@contextmanager
def _repo_lock(root: Path) -> Iterator[EditLock]:
def _repo_lock(root: Path) -> Generator[EditLock]:
"""Hold the checkout's edit lock (see `EditLock`) until the block ends."""
with EditLock(root) as lock:
lock.acquire()
Expand Down Expand Up @@ -619,7 +619,7 @@ def _undo_newest(root: Path) -> TransactionOutcome | None:


@contextmanager
def transaction(repo_root: Path) -> Iterator[EditTransaction]:
def transaction(repo_root: Path) -> Generator[EditTransaction]:
"""`with transaction(root) as tx: tx.stage(...)`; rolls back on exception."""
tx = EditTransaction(repo_root)
try:
Expand Down
4 changes: 2 additions & 2 deletions codebase_rag/embedded_graph/limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import annotations

import time
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager
from contextvars import ContextVar
from dataclasses import dataclass
Expand Down Expand Up @@ -39,7 +39,7 @@ def passed(self) -> bool:


@contextmanager
def running_until(deadline: Deadline) -> Iterator[None]:
def running_until(deadline: Deadline) -> Generator[None]:
token = _current.set(deadline)
try:
yield
Expand Down
4 changes: 2 additions & 2 deletions codebase_rag/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import os
import sys
from collections.abc import Iterator
from collections.abc import Generator
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -229,7 +229,7 @@ def _failed_call(message: str) -> CallToolResult:


@contextlib.contextmanager
def _service_lifecycle(ingestor: MemgraphIngestor) -> Iterator[None]:
def _service_lifecycle(ingestor: MemgraphIngestor) -> Generator[None]:
"""Manage shared service lifetimes for the MCP server.

Opens the Memgraph ingestor connection and releases the vector store client
Expand Down
3 changes: 2 additions & 1 deletion codebase_rag/parsers/class_ingest/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DeferredCppInherit,
DeferredInherit,
FunctionLocation,
FunctionLocations,
FunctionSpanKey,
NodeType,
PendingTypeFact,
Expand Down Expand Up @@ -387,7 +388,7 @@ class ClassIngestMixin:
rust_impl_owner_module: dict[str, str]
rehydrated_definition_paths: dict[str, str]
go_interfaces: dict[str, go_ifaces.GoInterfaceDecl]
function_locations: dict[FunctionSpanKey, FunctionLocation]
function_locations: FunctionLocations
cpp_definition_spans: dict[str, list[CppDefinitionSpan]]
_deferred_forward_decls: list[_DeferredForwardDecl]
_deferred_parent_links: list[DeferredParentLink]
Expand Down
4 changes: 3 additions & 1 deletion codebase_rag/parsers/definition_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ def _add_dependency(
cs.NodeLabel.EXTERNAL_PACKAGE, {cs.KEY_NAME: dep_name}
)

rel_properties = {cs.KEY_VERSION_SPEC: dep_spec} if dep_spec else {}
rel_properties: PropertyDict = (
{cs.KEY_VERSION_SPEC: dep_spec} if dep_spec else {}
)
if properties:
rel_properties |= properties

Expand Down
8 changes: 5 additions & 3 deletions codebase_rag/parsers/java/variable_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ class JavaVariableAnalyzerMixin:
_lookup_in_progress: set[str]
# Annotation only, never a def: this mixin precedes JavaMethodResolverMixin
# in the MRO, so even an @abstractmethod stub here would SHADOW the real
# implementation and silently resolve every call to None.
# implementation and silently resolve every call to None. `...` because a
# Callable's parameters are positional-only, and ty rejects that as an
# override of the resolver's methods, whose parameters have names.
_do_resolve_java_method_call: Callable[..., tuple[str, str] | None]
_declared_return_type_of: Callable[[str], str | None]
_resolve_java_method_return_type: Callable[[str, str], str | None]
_declared_return_type_of: Callable[..., str | None]
_resolve_java_method_return_type: Callable[..., str | None]

@abstractmethod
def _resolve_java_type_name(self, type_name: str, module_qn: str) -> str: ...
Expand Down
5 changes: 2 additions & 3 deletions codebase_rag/parsers/js_ts/module_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
if TYPE_CHECKING:
from ...services import IngestorProtocol
from ...types_defs import (
FunctionLocation,
FunctionLocations,
FunctionRegistryTrieProtocol,
FunctionSpanKey,
LanguageQueries,
SimpleNameLookup,
)
Expand All @@ -54,7 +53,7 @@ class JsTsModuleSystemMixin:
simple_name_lookup: SimpleNameLookup
module_qn_to_file_path: dict[str, Path]
import_processor: ImportProcessor
function_locations: dict[FunctionSpanKey, FunctionLocation]
function_locations: FunctionLocations
_processed_imports: set[str]

@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions codebase_rag/sqlite_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import json
import sqlite3
import threading
from collections.abc import Iterator, Sequence
from collections.abc import Generator, Sequence
from contextlib import contextmanager
from pathlib import Path
from typing import NamedTuple
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(self, conn: sqlite3.Connection) -> None:
self._lock = threading.Lock()

@contextmanager
def _write(self) -> Iterator[sqlite3.Connection]:
def _write(self) -> Generator[sqlite3.Connection]:
# The connection's own context manager commits, or rolls back when
# the block raises, so a failed batch leaves no half-written point.
with self._lock, self._conn:
Expand Down
6 changes: 3 additions & 3 deletions codebase_rag/stack/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time
import urllib.error
import urllib.request
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager
from http.client import HTTPMessage
from typing import IO, NamedTuple, Protocol
Expand Down Expand Up @@ -199,7 +199,7 @@ def _login_refused(report: MgclientProbeReport) -> bool:


@contextmanager
def _stderr_into(runtime: _CRuntime, capture: IO[bytes]) -> Iterator[None]:
def _stderr_into(runtime: _CRuntime, capture: IO[bytes]) -> Generator[None]:
try:
saved: int | None = runtime.dup(cs.NATIVE_STDERR_FD)
except OSError:
Expand Down Expand Up @@ -232,7 +232,7 @@ def _stderr_into(runtime: _CRuntime, capture: IO[bytes]) -> Iterator[None]:


@contextmanager
def _mgclient_stderr_to_debug_log() -> Iterator[None]:
def _mgclient_stderr_to_debug_log() -> Generator[None]:
with _NATIVE_STDERR_LOCK, tempfile.TemporaryFile() as capture:
# Text Python still buffers for the terminal belongs there, not in
# the capture.
Expand Down
6 changes: 3 additions & 3 deletions codebase_rag/sync_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import os
import uuid
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager
from pathlib import Path
from typing import NamedTuple
Expand Down Expand Up @@ -119,7 +119,7 @@ def release_project_claim(
@contextmanager
def project_claim(
ingestor: QueryProtocol, project_name: str, repo: Path, *, assume_yes: bool
) -> Iterator[list[str] | None]:
) -> Generator[list[str] | None]:
"""Claim the project on `ingestor` for as long as the writer runs (#2411).

Raises `SyncRefusedError`, before anything is written, when the name is
Expand Down Expand Up @@ -151,7 +151,7 @@ def sync_marker_params(project_name: str) -> dict[str, PropertyValue]:


@contextmanager
def sync_owner() -> Iterator[dict[str, PropertyValue]]:
def sync_owner() -> Generator[dict[str, PropertyValue]]:
"""Who this sync is, for its marker; registered as running while held."""
token = uuid.uuid4().hex
RUNNING_SYNC_TOKENS.add(token)
Expand Down
4 changes: 2 additions & 2 deletions codebase_rag/sync_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import sys
import threading
import time
from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -330,7 +330,7 @@ def _reenter(key: str) -> bool:
@contextmanager
def repo_sync_lock(
repo_path: Path, project_name: str, *, wait: bool = False
) -> Iterator[None]:
) -> Generator[None]:
"""Hold the sync lock of the checkout at `repo_path` for the block.

Raises `SyncInProgressError`, naming the holder, when another writer
Expand Down
4 changes: 2 additions & 2 deletions codebase_rag/tools/health_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import importlib
import os
import subprocess
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager

import httpx
Expand All @@ -27,7 +27,7 @@


@contextmanager
def _backend_connection() -> Iterator[ConnectionProtocol]:
def _backend_connection() -> Generator[ConnectionProtocol]:
"""Open a connection to whichever graph engine is configured.

Health output must describe the backend actually in use, so this
Expand Down
10 changes: 9 additions & 1 deletion codebase_rag/unixcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from collections.abc import Callable

import torch
from torch import nn
from transformers import RobertaConfig, RobertaModel, RobertaTokenizer
Expand Down Expand Up @@ -96,7 +98,7 @@ def decode(self, source_ids: torch.Tensor) -> list[list[str]]:
predictions.append(prediction)
return predictions

def forward(self, source_ids: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
def _embed(self, source_ids: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
pad_id = self.config.pad_token_id
assert pad_id is not None
mask = source_ids.ne(pad_id)
Expand All @@ -107,6 +109,12 @@ def forward(self, source_ids: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]
).unsqueeze(-1)
return token_embeddings, sentence_embeddings

# nn.Module declares `forward` as a writable Callable attribute, and ty
# rejects a `def forward` as narrowing it (invalid-mutable-override,
# astral-sh/ty issue 4823). Assigning the method to an attribute of that
# declared shape keeps the override valid and the return type precise.
forward: Callable[..., tuple[torch.Tensor, torch.Tensor]] = _embed

def generate(
self,
source_ids: torch.Tensor,
Expand Down
6 changes: 3 additions & 3 deletions evals/go_build_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import shutil
import subprocess
import tempfile
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager
from dataclasses import dataclass, field
from graphlib import TopologicalSorter
Expand Down Expand Up @@ -504,7 +504,7 @@ class BuildFacts(NamedTuple):


@contextmanager
def _environment(**values: str) -> Iterator[None]:
def _environment(**values: str) -> Generator[None]:
old = {key: os.environ.get(key) for key in values}
os.environ.update(values)
try:
Expand Down Expand Up @@ -612,7 +612,7 @@ def index(root: Path, frontend: str) -> _StatefulIngestor:


@contextmanager
def _host() -> Iterator[None]:
def _host() -> Generator[None]:
yield


Expand Down
4 changes: 2 additions & 2 deletions evals/oracle_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from __future__ import annotations

from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator
from contextlib import contextmanager

import typer
Expand Down Expand Up @@ -49,7 +49,7 @@ def require_oracle(


@contextmanager
def oracle_unavailable_exits() -> Iterator[None]:
def oracle_unavailable_exits() -> Generator[None]:
try:
yield
except NodeOracleUnavailable as unavailable:
Expand Down
Loading
Loading