Skip to content

Commit

Permalink
revert: wrong typed dict
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Dec 5, 2022
1 parent 2512f7a commit b5952b8
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 24 deletions.
9 changes: 2 additions & 7 deletions src/bentoml/_internal/io_descriptors/base.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/io_descriptors/file.py
Expand Up @@ -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

Expand Down Expand Up @@ -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"])
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/io_descriptors/image.py
Expand Up @@ -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

Expand Down Expand Up @@ -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}")

Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/io_descriptors/json.py
Expand Up @@ -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

Expand Down Expand Up @@ -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"]:
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/io_descriptors/multipart.py
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/io_descriptors/numpy.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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"])
Expand Down
5 changes: 2 additions & 3 deletions src/bentoml/_internal/io_descriptors/pandas.py
Expand Up @@ -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

Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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"])
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/io_descriptors/text.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/server/grpc/servicer.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit b5952b8

Please sign in to comment.