Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid editing list in during iteration #4809

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/_bentoml_sdk/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,19 @@ def numpy_prepare_pydantic_annotations(
dtype = np.dtype(get_args(args[1])[0]).name if args else None
shape: tuple[int, ...] | None = None

_, remaining_annotations = _known_annotated_metadata.collect_known_metadata(
annotations
)
for i, annotation in reversed(list(enumerate(remaining_annotations))):
_, other_annotations = _known_annotated_metadata.collect_known_metadata(annotations)
remaining_annotations = []
for annotation in other_annotations:
if isinstance(annotation, Shape):
shape = annotation.dimensions
del remaining_annotations[i]
elif isinstance(annotation, DType):
if dtype is not None and dtype != annotation.dtype:
raise ValueError(
f"Conflicting dtype annotations: {dtype} and {annotation.dtype}"
)
dtype = annotation.dtype
del remaining_annotations[i]
else:
remaining_annotations.append(annotation)
return source, [TensorSchema("numpy-array", dtype, shape), *remaining_annotations]


Expand Down
Loading