Skip to content

Commit

Permalink
Migrate new command annotation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed Dec 12, 2024
1 parent 8e81542 commit 212e876
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 2 additions & 7 deletions api/src/opentrons/protocol_engine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
)

from pydantic import (
ConfigDict,
BaseModel,
Field,
RootModel,
StrictBool,
StrictFloat,
StrictInt,
StrictStr,
validator,
Extra,
)
from typing_extensions import Literal, TypeGuard

Expand Down Expand Up @@ -1156,11 +1155,7 @@ class CustomCommandAnnotation(BaseCommandAnnotation):
"""Annotates a group of atomic commands in some manner that Opentrons software does not anticipate or originate."""

annotationType: Literal["custom"] = "custom"

class Config:
"""Config to allow extra, non-defined properties."""

extra = Extra.allow
model_config = ConfigDict(extra="allow")


CommandAnnotation = Union[SecondOrderCommandAnnotation, CustomCommandAnnotation]
Expand Down
8 changes: 5 additions & 3 deletions api/src/opentrons/protocol_runner/json_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class CommandTranslatorError(Exception):
# serializer. To improve performance, TypeAdapters are instantiated once.
# See https://docs.pydantic.dev/latest/concepts/performance/#typeadapter-instantiated-once
LabwareLocationAdapter: TypeAdapter[LabwareLocation] = TypeAdapter(LabwareLocation)
CommandAnnotationAdapter: TypeAdapter[CommandAnnotation] = TypeAdapter(
CommandAnnotation
)


def _translate_labware_command(
Expand Down Expand Up @@ -301,9 +304,8 @@ def translate_command_annotations(
return []
else:
command_annotations: List[CommandAnnotation] = [
parse_obj_as(
CommandAnnotation, # type: ignore[arg-type]
command_annotation.dict(),
CommandAnnotationAdapter.validate_python(
command_annotation.model_dump(),
)
for command_annotation in protocol.commandAnnotations
]
Expand Down

0 comments on commit 212e876

Please sign in to comment.