Skip to content

Commit 24baac5

Browse files
committed
Address review: fix Awaitable double-await, default value, phantom imports
- StreamObserverProtocol.__call__: returns None (async def already wraps in Awaitable) - PermissionedQueryManagerProtocol.visible_to_user: default is None not Ellipsis - Drop unused Awaitable and Optional imports from protocols - Remove phantom protocol imports + multi-line comment blocks from tool_factory, base_component, Managers (rely on canonical opencontractserver.types.protocols) - Collapse multi-line re-export comment in core_vector_stores - Type _process_single_upload/_fail_upload upload_id as UUID (matches model) - Type agents/admin.get_queryset return as QuerySet[AgentActionResult] - Type UserFeedbackManager.get_or_none *args/**kwargs as Any - Document why StreamObserverProtocol is not @runtime_checkable
1 parent 879503d commit 24baac5

7 files changed

Lines changed: 13 additions & 34 deletions

File tree

opencontractserver/agents/admin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any
2-
31
from django.contrib import admin
2+
from django.db.models import QuerySet
43
from django.http import HttpRequest
54
from django.utils.html import format_html
65
from guardian.admin import GuardedModelAdmin
@@ -268,7 +267,7 @@ def execution_metadata_display(self, obj: AgentActionResult) -> str:
268267

269268
execution_metadata_display.short_description = "Execution Metadata"
270269

271-
def get_queryset(self, request: HttpRequest) -> Any:
270+
def get_queryset(self, request: HttpRequest) -> QuerySet[AgentActionResult]:
272271
"""Optimize queryset with select_related."""
273272
return (
274273
super()

opencontractserver/llms/tools/tool_factory.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
from typing import Any, Callable, Optional
77

88
from opencontractserver.llms.types import AgentFramework
9-
from opencontractserver.types.protocols import ToolProtocol # noqa: F401
109

1110
logger = logging.getLogger(__name__)
1211

13-
# ``ToolProtocol`` mirrors the public surface of :class:`CoreTool` so that
14-
# framework adapters (e.g. PydanticAI) can accept any object exposing the
15-
# same ``name``/``description``/``parameters``/``requires_approval`` API.
16-
1712

1813
def build_inject_params_for_context(
1914
tool: "CoreTool",

opencontractserver/llms/vector_stores/core_vector_stores.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,7 @@ async def async_search(self, query: VectorSearchQuery) -> list[VectorSearchResul
11031103
return results
11041104

11051105

1106-
# ``VectorStoreProtocol`` is imported above so that downstream callers can
1107-
# annotate parameters as ``VectorStoreProtocol`` and mypy will accept any
1108-
# class implementing the same surface as :class:`CoreAnnotationVectorStore`.
1109-
# Re-export to make the dependency explicit for static analysis tools.
1106+
# Re-exported so downstream callers can annotate against the protocol.
11101107
__all__ = [
11111108
"CoreAnnotationVectorStore",
11121109
"VectorSearchQuery",

opencontractserver/pipeline/base/base_component.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55

66
from django.conf import settings
77

8-
from opencontractserver.types.protocols import PipelineComponentProtocol # noqa: F401
9-
108
logger = logging.getLogger(__name__)
119

12-
# ``PipelineComponentProtocol`` (re-exported here) describes the duck-typed
13-
# surface that registry consumers rely on (``title``, ``description``,
14-
# ``author``, ``dependencies``). Concrete subclasses of
15-
# :class:`PipelineComponentBase` (parsers, embedders, thumbnailers,
16-
# post-processors) all satisfy that protocol structurally.
17-
1810

1911
class PipelineComponentBase(ABC):
2012
"""

opencontractserver/shared/Managers.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
PermissionQuerySet,
1313
UserFeedbackQuerySet,
1414
)
15-
from opencontractserver.types.protocols import ( # noqa: F401
16-
PermissionedQueryManagerProtocol,
17-
)
18-
19-
# ``PermissionedQueryManagerProtocol`` (in ``opencontractserver.types.protocols``)
20-
# describes the public ``visible_to_user(user)`` contract that every manager
21-
# below honours. Importing it here makes the dependency explicit so callers
22-
# typing on the protocol get static checks for free.
2315

2416
if TYPE_CHECKING:
2517
from django.contrib.auth import get_user_model
@@ -247,7 +239,7 @@ def visible_to_user(self, user: User) -> QuerySet:
247239
"""Delegate to the queryset's visible_to_user method"""
248240
return self.get_queryset().visible_to_user(user)
249241

250-
def get_or_none(self, *args, **kwargs) -> Optional[Any]:
242+
def get_or_none(self, *args: Any, **kwargs: Any) -> Optional[Any]:
251243
try:
252244
return self.get(*args, **kwargs)
253245
except self.model.DoesNotExist:

opencontractserver/types/protocols.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
from __future__ import annotations
2222

23-
from collections.abc import Awaitable
2423
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
2524

2625
if TYPE_CHECKING:
@@ -149,7 +148,7 @@ class PermissionedQueryManagerProtocol(Protocol):
149148
accept ``None`` (treated as anonymous) still satisfy the protocol.
150149
"""
151150

152-
def visible_to_user(self, user: Any | None = ...) -> QuerySet[Any]:
151+
def visible_to_user(self, user: Any | None = None) -> QuerySet[Any]:
153152
"""Return a queryset filtered to objects visible to ``user``."""
154153
...
155154

@@ -165,9 +164,13 @@ class StreamObserverProtocol(Protocol):
165164
Mirrors :class:`opencontractserver.llms.types.StreamObserver` so it
166165
can be referenced from non-LLM code (notifications, websockets)
167166
without importing ``llms.types``.
167+
168+
Not ``@runtime_checkable``: ``isinstance`` checks against an
169+
async-only ``__call__`` protocol cannot distinguish sync from async
170+
callables, so we leave verification to the static type checker.
168171
"""
169172

170-
async def __call__(self, event: Any) -> Awaitable[None]: ...
173+
async def __call__(self, event: Any) -> None: ...
171174

172175

173176
__all__ = [

opencontractserver/worker_uploads/tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
from datetime import timedelta
1818
from typing import Any
19+
from uuid import UUID
1920

2021
from celery import shared_task
2122
from django.conf import settings
@@ -180,7 +181,7 @@ def recover_stalled_uploads() -> dict[str, int]:
180181
return {"recovered": count}
181182

182183

183-
def _process_single_upload(upload_id: Any) -> None:
184+
def _process_single_upload(upload_id: UUID) -> None:
184185
"""
185186
Process one WorkerDocumentUpload: create Document, annotations,
186187
embeddings, and add to the target corpus.
@@ -487,7 +488,7 @@ def _get_vector_field(dimension: int) -> str | None:
487488
return _VECTOR_FIELD_MAP.get(dimension)
488489

489490

490-
def _fail_upload(upload_id: Any, error_message: str) -> None:
491+
def _fail_upload(upload_id: UUID, error_message: str) -> None:
491492
"""Mark an upload as FAILED and clean up its staging file."""
492493
upload = WorkerDocumentUpload.objects.filter(id=upload_id).first()
493494
if upload is None:

0 commit comments

Comments
 (0)