Skip to content

Commit

Permalink
provide method to cast labware defs and types to typeddict
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Oct 1, 2024
1 parent 25a0ecd commit dc69902
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion shared-data/python/opentrons_shared_data/labware/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from typing import Dict, List, NewType, Union
from typing_extensions import Literal, TypedDict, NotRequired

from .labware_definition import WellSegment as WellSegmentDef

LabwareUri = NewType("LabwareUri", str)

Expand Down Expand Up @@ -176,10 +176,21 @@ class RoundedRectangularSegment(TypedDict):
SphericalSegment,
]

@staticmethod
def ToWellSegmentDict(segment: Union[WellSegment,WellSegmentDef]) -> WellSegment:
if isinstance(segment, WellSegmentDef):
return typing.cast(WellSegment, segment.model_dump(exclude_none=True, exclude_unset=True))
return segment


class InnerWellGeometry(TypedDict):
sections: List[WellSegment]

@staticmethod
def ToInnerWellGeometryDict(inner_well_geometry: Union[InnerWellGeometry,InnerWellGeometryDef]) -> InnerWellGeometry:
return InnerWellGeometry([ToWellSegmentDict(section) for section in inner_well_geometry["sections"]])



class LabwareDefinition(TypedDict):
schemaVersion: Literal[2]
Expand Down

0 comments on commit dc69902

Please sign in to comment.