From 75acab0e61dfc33225ff1b090c5ecd705bfe7053 Mon Sep 17 00:00:00 2001 From: Adam Liter Date: Mon, 6 May 2024 01:47:44 -0600 Subject: [PATCH] fix: annotation preparation list iteration bug (#4701) * fix: annotation preparation list iteration bug * docs: fix typo --- docs/source/guides/iotypes.rst | 4 ++-- src/_bentoml_sdk/_pydantic.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/guides/iotypes.rst b/docs/source/guides/iotypes.rst index cb0a8e21f11..cacae7e6ab5 100644 --- a/docs/source/guides/iotypes.rst +++ b/docs/source/guides/iotypes.rst @@ -207,7 +207,7 @@ BentoML supports various tensor types such as ``numpy.ndarray``, ``torch.Tensor` .. code-block:: python import torch - from bentoml.validators import Shape, Dtype + from bentoml.validators import Shape, DType from typing import Annotated # Python 3.9 or above from typing_extensions import Annotated # Older than 3.9 from pydantic import Field @@ -218,7 +218,7 @@ BentoML supports various tensor types such as ``numpy.ndarray``, ``torch.Tensor` @bentoml.api def classify( self, - input: Annotated[torch.Tensor, Shape((1, 4)), Dtype("float32")] + input: Annotated[torch.Tensor, Shape((1, 4)), DType("float32")] = Field(description="A 1x4 tensor with float32 dtype") ) -> np.ndarray: ... diff --git a/src/_bentoml_sdk/_pydantic.py b/src/_bentoml_sdk/_pydantic.py index ae4e49d53da..765549fbeb1 100644 --- a/src/_bentoml_sdk/_pydantic.py +++ b/src/_bentoml_sdk/_pydantic.py @@ -53,7 +53,7 @@ def numpy_prepare_pydantic_annotations( _, remaining_annotations = _known_annotated_metadata.collect_known_metadata( annotations ) - for i, annotation in enumerate(remaining_annotations[:]): + for i, annotation in reversed(list(enumerate(remaining_annotations))): if isinstance(annotation, Shape): shape = annotation.dimensions del remaining_annotations[i] @@ -80,7 +80,7 @@ def torch_prepare_pydantic_annotations( _, remaining_annotations = _known_annotated_metadata.collect_known_metadata( annotations ) - for i, annotation in enumerate(remaining_annotations[:]): + for i, annotation in reversed(list(enumerate(remaining_annotations))): if isinstance(annotation, Shape): shape = annotation.dimensions del remaining_annotations[i] @@ -106,7 +106,7 @@ def tf_prepare_pydantic_annotations( _, remaining_annotations = _known_annotated_metadata.collect_known_metadata( annotations ) - for i, annotation in enumerate(remaining_annotations[:]): + for i, annotation in reversed(list(enumerate(remaining_annotations))): if isinstance(annotation, Shape): shape = annotation.dimensions del remaining_annotations[i] @@ -169,7 +169,7 @@ def pathlib_prepare_pydantic_annotations( annotations ) content_type: str | None = None - for i, annotation in enumerate(remaining_annotations[:]): + for i, annotation in reversed(list(enumerate(remaining_annotations))): if isinstance(annotation, ContentType): content_type = annotation.content_type del remaining_annotations[i]