Refactor: reformat all code for lefthook using ruff and gofmt (#16585)

This commit is contained in:
Wang Qi
2026-07-03 12:53:39 +08:00
committed by GitHub
parent 19fcb4a981
commit 6a4b9be426
588 changed files with 11123 additions and 15412 deletions

View File

@@ -1,4 +1,5 @@
"""Interface definitions"""
import abc
import uuid
from abc import ABC, abstractmethod
@@ -8,14 +9,7 @@ from typing import Any, Dict, Generator, TypeVar, Generic, Callable, TypeAlias
from collections.abc import Iterator
from anthropic import BaseModel
from common.data_source.models import (
Document,
KeyRecord,
SlimDocument,
ConnectorCheckpoint,
ConnectorFailure,
SecondsSinceUnixEpoch, GenerateSlimDocumentOutput
)
from common.data_source.models import Document, KeyRecord, SlimDocument, ConnectorCheckpoint, ConnectorFailure, SecondsSinceUnixEpoch, GenerateSlimDocumentOutput
class IncrementalCapability(IntEnum):
@@ -25,6 +19,7 @@ class IncrementalCapability(IntEnum):
CURSOR -- "give me everything since cursor X"; opaque cursor persisted across syncs.
FINGERPRINT -- list_keys() returns (key, fingerprint) cheaply; bodies fetched lazily.
"""
FULL_RESYNC = 0
CURSOR = 1
FINGERPRINT = 2
@@ -32,6 +27,7 @@ class IncrementalCapability(IntEnum):
GenerateDocumentsOutput = Iterator[list[Document]]
class LoadConnector(ABC):
"""Load connector interface"""
@@ -165,9 +161,7 @@ class CredentialsProviderInterface(abc.ABC, Generic[T]):
raise NotImplementedError
class StaticCredentialsProvider(
CredentialsProviderInterface["StaticCredentialsProvider"]
):
class StaticCredentialsProvider(CredentialsProviderInterface["StaticCredentialsProvider"]):
"""Implementation (a very simple one!) to handle static credentials."""
def __init__(
@@ -224,9 +218,7 @@ class BaseConnector(abc.ABC, Generic[CT]):
@staticmethod
def parse_metadata(metadata: dict[str, Any]) -> list[str]:
"""Parse the metadata for a document/chunk into a string to pass to Generative AI as additional context"""
custom_parser_req_msg = (
"Specific metadata parsing required, connector has not implemented it."
)
custom_parser_req_msg = "Specific metadata parsing required, connector has not implemented it."
metadata_lines = []
for metadata_key, metadata_value in metadata.items():
if isinstance(metadata_value, str):
@@ -234,7 +226,7 @@ class BaseConnector(abc.ABC, Generic[CT]):
elif isinstance(metadata_value, list):
if not all([isinstance(val, str) for val in metadata_value]):
raise RuntimeError(custom_parser_req_msg)
metadata_lines.append(f'{metadata_key}: {", ".join(metadata_value)}')
metadata_lines.append(f"{metadata_key}: {', '.join(metadata_value)}")
else:
raise RuntimeError(custom_parser_req_msg)
return metadata_lines
@@ -342,14 +334,10 @@ class CheckpointOutputWrapper(Generic[CT]):
elif isinstance(document_or_failure, ConnectorFailure):
yield None, document_or_failure, None
else:
raise ValueError(
f"Invalid document_or_failure type: {type(document_or_failure)}"
)
raise ValueError(f"Invalid document_or_failure type: {type(document_or_failure)}")
if self.next_checkpoint is None:
raise RuntimeError(
"Checkpoint is None. This should never happen - the connector should always return a checkpoint."
)
raise RuntimeError("Checkpoint is None. This should never happen - the connector should always return a checkpoint.")
yield None, None, self.next_checkpoint
@@ -464,4 +452,3 @@ class FingerprintConnector(ABC):
content_hash for that key (or when no persisted fingerprint exists).
"""
raise NotImplementedError