From b5952b8cb4d2c8c8cf9acaa8c8b4800047becb01 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:51:41 -0800 Subject: [PATCH] revert: wrong typed dict Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- src/bentoml/_internal/io_descriptors/base.py | 9 ++------- src/bentoml/_internal/io_descriptors/file.py | 3 +-- src/bentoml/_internal/io_descriptors/image.py | 3 +-- src/bentoml/_internal/io_descriptors/json.py | 3 +-- src/bentoml/_internal/io_descriptors/multipart.py | 3 +-- src/bentoml/_internal/io_descriptors/numpy.py | 3 +-- src/bentoml/_internal/io_descriptors/pandas.py | 5 ++--- src/bentoml/_internal/io_descriptors/text.py | 3 +-- src/bentoml/_internal/server/grpc/servicer.py | 3 +-- 9 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/bentoml/_internal/io_descriptors/base.py b/src/bentoml/_internal/io_descriptors/base.py index 5e95cc4a262..c64b8034009 100644 --- a/src/bentoml/_internal/io_descriptors/base.py +++ b/src/bentoml/_internal/io_descriptors/base.py @@ -30,17 +30,12 @@ ) OpenAPIResponse = dict[str, str | dict[str, MediaType] | dict[str, t.Any]] - class SpecDict(t.TypedDict): - id: str - args: t.NotRequired[dict[str, t.Any]] - - IO_DESCRIPTOR_REGISTRY: dict[str, type[IODescriptor[t.Any]]] = {} IOType = t.TypeVar("IOType") -def from_spec(spec: SpecDict) -> IODescriptor[t.Any]: +def from_spec(spec: dict[str, t.Any]) -> IODescriptor[t.Any]: if "id" not in spec: raise InvalidArgument(f"IO descriptor spec ({spec}) missing ID.") return IO_DESCRIPTOR_REGISTRY[spec["id"]].from_spec(spec) @@ -133,7 +128,7 @@ def to_spec(self) -> dict[str, t.Any]: @classmethod @abstractmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: raise NotImplementedError @abstractmethod diff --git a/src/bentoml/_internal/io_descriptors/file.py b/src/bentoml/_internal/io_descriptors/file.py index 90f48487254..ed4ccefe01c 100644 --- a/src/bentoml/_internal/io_descriptors/file.py +++ b/src/bentoml/_internal/io_descriptors/file.py @@ -30,7 +30,6 @@ from bentoml.grpc.v1 import service_pb2 as pb - from .base import SpecDict from .base import OpenAPIResponse from ..context import InferenceApiContext as Context @@ -144,7 +143,7 @@ def _from_sample(self, sample: FileType | str) -> FileType: return sample @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in File spec: {spec}") return cls(**spec["args"]) diff --git a/src/bentoml/_internal/io_descriptors/image.py b/src/bentoml/_internal/io_descriptors/image.py index d9f78c9d7e7..ffdd55369e0 100644 --- a/src/bentoml/_internal/io_descriptors/image.py +++ b/src/bentoml/_internal/io_descriptors/image.py @@ -36,7 +36,6 @@ from bentoml.grpc.v1 import service_pb2 as pb from .. import external_typing as ext - from .base import SpecDict from .base import OpenAPIResponse from ..context import InferenceApiContext as Context @@ -246,7 +245,7 @@ def to_spec(self) -> dict[str, t.Any]: } @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in Image spec: {spec}") diff --git a/src/bentoml/_internal/io_descriptors/json.py b/src/bentoml/_internal/io_descriptors/json.py index f32dbda8020..08c1dc18b59 100644 --- a/src/bentoml/_internal/io_descriptors/json.py +++ b/src/bentoml/_internal/io_descriptors/json.py @@ -35,7 +35,6 @@ from typing_extensions import Self from .. import external_typing as ext - from .base import SpecDict from .base import OpenAPIResponse from ..context import InferenceApiContext as Context @@ -236,7 +235,7 @@ def to_spec(self) -> dict[str, t.Any]: } @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in JSON spec: {spec}") if "has_pydantic_model" in spec["args"] and spec["args"]["has_pydantic_model"]: diff --git a/src/bentoml/_internal/io_descriptors/multipart.py b/src/bentoml/_internal/io_descriptors/multipart.py index 108261b1144..2f59866df56 100644 --- a/src/bentoml/_internal/io_descriptors/multipart.py +++ b/src/bentoml/_internal/io_descriptors/multipart.py @@ -25,7 +25,6 @@ from bentoml.grpc.v1 import service_pb2 as pb - from .base import SpecDict from .base import OpenAPIResponse from ..types import LazyType from ..context import InferenceApiContext as Context @@ -203,7 +202,7 @@ def to_spec(self) -> dict[str, t.Any]: } @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in Multipart spec: {spec}") return Multipart( diff --git a/src/bentoml/_internal/io_descriptors/numpy.py b/src/bentoml/_internal/io_descriptors/numpy.py index 8508bb142b0..a928213eafe 100644 --- a/src/bentoml/_internal/io_descriptors/numpy.py +++ b/src/bentoml/_internal/io_descriptors/numpy.py @@ -28,7 +28,6 @@ from bentoml.grpc.v1 import service_pb2 as pb from .. import external_typing as ext - from .base import SpecDict from .base import OpenAPIResponse from ..context import InferenceApiContext as Context else: @@ -253,7 +252,7 @@ def to_spec(self) -> dict[str, t.Any]: } @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in NumpyNdarray spec: {spec}") res = NumpyNdarray(**spec["args"]) diff --git a/src/bentoml/_internal/io_descriptors/pandas.py b/src/bentoml/_internal/io_descriptors/pandas.py index 921a3f71bf7..28c7e0f08e9 100644 --- a/src/bentoml/_internal/io_descriptors/pandas.py +++ b/src/bentoml/_internal/io_descriptors/pandas.py @@ -35,7 +35,6 @@ from bentoml.grpc.v1 import service_pb2 as pb from .. import external_typing as ext - from .base import SpecDict from .base import OpenAPIResponse from ..context import InferenceApiContext as Context @@ -454,7 +453,7 @@ def to_spec(self) -> dict[str, t.Any]: } @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in PandasDataFrame spec: {spec}") res = PandasDataFrame(**spec["args"]) @@ -901,7 +900,7 @@ def to_spec(self) -> dict[str, t.Any]: } @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: if "args" not in spec: raise InvalidArgument(f"Missing args key in PandasSeries spec: {spec}") res = PandasSeries(**spec["args"]) diff --git a/src/bentoml/_internal/io_descriptors/text.py b/src/bentoml/_internal/io_descriptors/text.py index 944840b11ff..ed9127069a2 100644 --- a/src/bentoml/_internal/io_descriptors/text.py +++ b/src/bentoml/_internal/io_descriptors/text.py @@ -19,7 +19,6 @@ from google.protobuf import wrappers_pb2 from typing_extensions import Self - from .base import SpecDict from .base import OpenAPIResponse from ..context import InferenceApiContext as Context else: @@ -112,7 +111,7 @@ def to_spec(self) -> dict[str, t.Any]: return {"id": self.descriptor_id} @classmethod - def from_spec(cls, spec: SpecDict) -> Self: + def from_spec(cls, spec: dict[str, t.Any]) -> Self: return cls() def openapi_schema(self) -> Schema: diff --git a/src/bentoml/_internal/server/grpc/servicer.py b/src/bentoml/_internal/server/grpc/servicer.py index d87f0d3f182..e5e7209b8f1 100644 --- a/src/bentoml/_internal/server/grpc/servicer.py +++ b/src/bentoml/_internal/server/grpc/servicer.py @@ -35,7 +35,6 @@ from bentoml.grpc.types import BentoServicerContext from ...service.service import Service - from ...io_descriptors.base import SpecDict if LATEST_PROTOCOL_VERSION == "v1": from bentoml.grpc.v1 import service_pb2 as pb @@ -254,7 +253,7 @@ def _tuple_converter(d: NestedDictStrAny | None) -> NestedDictStrAny | None: def make_descriptor_spec( - spec: SpecDict, pb: type[ServiceMetadataResponse] + spec: dict[str, t.Any], pb: type[ServiceMetadataResponse] ) -> ServiceMetadataResponse.DescriptorMetadata: from ...io_descriptors.json import parse_dict_to_proto