Skip to content

Commit 82e3b02

Browse files
committed
refactor: update all deprecated usage of Type
1 parent 48aad38 commit 82e3b02

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

python/cocoindex/convert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import uuid
99

1010
from enum import Enum
11-
from typing import Any, Callable, get_origin, Mapping, Type
11+
from typing import Any, Callable, get_origin, Mapping
1212
from .typing import (
1313
analyze_type_info,
1414
encode_enriched_type,
@@ -41,7 +41,7 @@ def encode_engine_value(value: Any) -> Any:
4141
def make_engine_value_decoder(
4242
field_path: list[str],
4343
src_type: dict[str, Any],
44-
dst_annotation: Type[Any] | None,
44+
dst_annotation: Any,
4545
) -> Callable[[Any], Any]:
4646
"""
4747
Make a decoder from an engine value to a Python value.
@@ -60,7 +60,7 @@ def make_engine_value_decoder(
6060
if (
6161
dst_annotation is None
6262
or dst_annotation is inspect.Parameter.empty
63-
or get_origin(dst_annotation) is Any
63+
or dst_annotation is Any
6464
):
6565
if src_type_kind == "Struct" or src_type_kind in TABLE_TYPES:
6666
raise ValueError(

python/cocoindex/flow.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
Generic,
1919
get_args,
2020
get_origin,
21-
Type,
2221
NamedTuple,
2322
cast,
2423
)
@@ -786,14 +785,14 @@ async def _update_flow(name: str, fl: Flow) -> tuple[str, _engine.IndexUpdateInf
786785

787786

788787
def _get_data_slice_annotation_type(
789-
data_slice_type: Type[DataSlice[T] | inspect._empty],
790-
) -> Type[T] | None:
788+
data_slice_type: type[DataSlice[T] | inspect._empty],
789+
) -> type[T] | None:
791790
type_args = get_args(data_slice_type)
792791
if data_slice_type is inspect.Parameter.empty or data_slice_type is DataSlice:
793792
return None
794793
if get_origin(data_slice_type) != DataSlice or len(type_args) != 1:
795794
raise ValueError(f"Expect a DataSlice[T] type, but got {data_slice_type}")
796-
return cast(Type[T] | None, type_args[0])
795+
return cast(type[T] | None, type_args[0])
797796

798797

799798
_transform_flow_name_builder = _NameBuilder()
@@ -892,7 +891,7 @@ async def _build_flow_info_async(self) -> TransformFlowInfo:
892891
engine_return_type = (
893892
_data_slice_state(output).engine_data_slice.data_type().schema()
894893
)
895-
python_return_type: Type[T] | None = _get_data_slice_annotation_type(
894+
python_return_type: type[T] | None = _get_data_slice_annotation_type(
896895
sig.return_annotation
897896
)
898897
result_decoder = make_engine_value_decoder(
@@ -952,7 +951,7 @@ def _transform_flow_wrapper(fn: Callable[..., DataSlice[T]]) -> TransformFlow[T]
952951
raise ValueError(
953952
f"Parameter `{param_name}` is not a parameter can be passed by name"
954953
)
955-
value_type_annotation: Type[T] | None = _get_data_slice_annotation_type(
954+
value_type_annotation: type[T] | None = _get_data_slice_annotation_type(
956955
param.annotation
957956
)
958957
if value_type_annotation is None:

python/cocoindex/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""All builtin functions."""
22

3-
from typing import Annotated, Any, Type, TYPE_CHECKING
3+
from typing import Annotated, Any, TYPE_CHECKING
44

55
from .typing import Float32, Vector, TypeAttr
66
from . import op, llm
@@ -47,13 +47,13 @@ class SentenceTransformerEmbedExecutor:
4747
spec: SentenceTransformerEmbed
4848
_model: "sentence_transformers.SentenceTransformer"
4949

50-
def analyze(self, text: Any) -> Type[Any]:
50+
def analyze(self, text: Any) -> type:
5151
import sentence_transformers # pylint: disable=import-outside-toplevel
5252

5353
args = self.spec.args or {}
5454
self._model = sentence_transformers.SentenceTransformer(self.spec.model, **args)
5555
dim = self._model.get_sentence_embedding_dimension()
56-
result: Type[Any] = Annotated[
56+
result: type = Annotated[
5757
Vector[Float32, dim], # type: ignore
5858
TypeAttr("cocoindex.io/vector_origin_text", text.analyzed_value),
5959
]

0 commit comments

Comments
 (0)