Skip to content

Commit

Permalink
fix: annotation preparation list iteration bug (#4701)
Browse files Browse the repository at this point in the history
* fix: annotation preparation list iteration bug

* docs: fix typo
  • Loading branch information
adamliter committed May 6, 2024
1 parent 9b30551 commit 75acab0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/source/guides/iotypes.rst
Expand Up @@ -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
Expand All @@ -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:
...
Expand Down
8 changes: 4 additions & 4 deletions src/_bentoml_sdk/_pydantic.py
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 75acab0

Please sign in to comment.