mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-04-02 06:12:46 +00:00
Refactor: fix type errors in remote parser and signals
- remote.py: add `if TYPE_CHECKING: assert` guards before the Azure client construction to narrow config.endpoint and config.api_key from str|None to str. The narrowing is safe: engine_is_valid() guarantees both are non-None when it returns True (api_key explicitly; endpoint via `not (engine=="azureai" and endpoint is None)` for the only valid engine). Asserts are wrapped in TYPE_CHECKING so they carry zero runtime cost. - signals.py: add full type annotations — return types, Any-typed sender parameter, and explicit logging_group argument replacing *args. Add `from __future__ import annotations` for consistent annotation style. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -377,6 +377,13 @@ class RemoteDocumentParser:
|
||||
str | None
|
||||
Extracted text, or None if the Azure call failed.
|
||||
"""
|
||||
if TYPE_CHECKING:
|
||||
# Callers must have already validated config via engine_is_valid():
|
||||
# engine_is_valid() asserts api_key is not None and (for azureai)
|
||||
# endpoint is not None, so these casts are provably safe.
|
||||
assert config.endpoint is not None
|
||||
assert config.api_key is not None
|
||||
|
||||
from azure.ai.documentintelligence import DocumentIntelligenceClient
|
||||
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest
|
||||
from azure.ai.documentintelligence.models import AnalyzeOutputOption
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
def get_parser(*args, **kwargs):
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def get_parser(logging_group: object = None) -> Any:
|
||||
from paperless.parsers.remote import RemoteDocumentParser
|
||||
|
||||
return RemoteDocumentParser(*args, **kwargs)
|
||||
return RemoteDocumentParser(logging_group)
|
||||
|
||||
|
||||
def get_supported_mime_types():
|
||||
def get_supported_mime_types() -> dict[str, str]:
|
||||
from django.conf import settings
|
||||
|
||||
from paperless.parsers.remote import RemoteDocumentParser
|
||||
@@ -20,7 +25,7 @@ def get_supported_mime_types():
|
||||
return RemoteDocumentParser.supported_mime_types()
|
||||
|
||||
|
||||
def remote_consumer_declaration(sender, **kwargs):
|
||||
def remote_consumer_declaration(sender: Any, **kwargs: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"parser": get_parser,
|
||||
"weight": 5,
|
||||
|
||||
Reference in New Issue
Block a user