mirror of
https://github.com/langgenius/dify.git
synced 2026-09-24 23:22:26 +08:00
chore(api): convert BaseTruncator from ABC to Protocol (#37199)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
@@ -7,26 +6,7 @@ from graphon.nodes.variable_assigner.common.helpers import UpdatedVariable
|
||||
from graphon.variables.segments import IntegerSegment, ObjectSegment, StringSegment
|
||||
from graphon.variables.types import SegmentType
|
||||
from services import variable_truncator as truncator_module
|
||||
from services.variable_truncator import BaseTruncator, TruncationResult, VariableTruncator
|
||||
|
||||
|
||||
class _AbstractPassthrough(BaseTruncator):
|
||||
def truncate(self, segment: Any) -> TruncationResult:
|
||||
return super().truncate(segment) # type: ignore[misc]
|
||||
|
||||
def truncate_variable_mapping(self, v: Mapping[str, Any]) -> tuple[Mapping[str, Any], bool]:
|
||||
return super().truncate_variable_mapping(v) # type: ignore[misc]
|
||||
|
||||
|
||||
class TestBaseTruncatorContract:
|
||||
def test_base_truncator_methods_should_execute_abstract_placeholders(self) -> None:
|
||||
passthrough = _AbstractPassthrough()
|
||||
|
||||
truncate_result = passthrough.truncate(StringSegment(value="x"))
|
||||
mapping_result = passthrough.truncate_variable_mapping({"a": 1})
|
||||
|
||||
assert truncate_result is None
|
||||
assert mapping_result is None
|
||||
from services.variable_truncator import VariableTruncator
|
||||
|
||||
|
||||
class TestVariableTruncatorAdditionalBehavior:
|
||||
|
||||
Reference in New Issue
Block a user