1
1
import re
2
- from typing import List , Dict , Tuple , Optional , Annotated
3
- from pydantic import field_validator , ConfigDict , BaseModel , Field , BeforeValidator
4
- from typing_extensions import Literal
2
+ from typing import List , Dict , Tuple , Optional , Annotated , Literal , TypeVar , Generic
3
+ from pydantic import (
4
+ field_validator ,
5
+ ConfigDict ,
6
+ BaseModel ,
7
+ Field ,
8
+ BeforeValidator ,
9
+ PlainSerializer ,
10
+ )
5
11
from dataclasses import dataclass
6
12
7
13
from . import types as pip_types , dev_types
@@ -21,6 +27,10 @@ def validate_opentrons_tiprack(v: str) -> str:
21
27
return v
22
28
23
29
30
+ EnumType = TypeVar ("EnumType" )
31
+ EnumSerializer = Annotated [EnumType , PlainSerializer (lambda v : v .value )]
32
+
33
+
24
34
# TODO (lc 12-5-2022) Ideally we can deprecate this
25
35
# at somepoint once we load pipettes by channels and type
26
36
@dataclass
@@ -286,12 +296,12 @@ class PipettePhysicalPropertiesDefinition(BaseModel):
286
296
description = "A list of pipette names that are compatible with this pipette." ,
287
297
alias = "backCompatNames" ,
288
298
)
289
- pipette_type : pip_types .PipetteModelType = Field (
299
+ pipette_type : EnumSerializer [ pip_types .PipetteModelType ] = Field (
290
300
...,
291
301
description = "The pipette model type (related to number of channels)." ,
292
302
alias = "model" ,
293
303
)
294
- display_category : pip_types .PipetteGenerationType = Field (
304
+ display_category : EnumSerializer [ pip_types .PipetteGenerationType ] = Field (
295
305
..., description = "The product model of the pipette." , alias = "displayCategory"
296
306
)
297
307
pick_up_tip_configurations : PickUpTipConfigurations = Field (
@@ -313,7 +323,7 @@ class PipettePhysicalPropertiesDefinition(BaseModel):
313
323
partial_tip_configurations : PartialTipDefinition = Field (
314
324
..., alias = "partialTipConfigurations"
315
325
)
316
- channels : pip_types .PipetteChannelType = Field (
326
+ channels : EnumSerializer [ pip_types .PipetteChannelType ] = Field (
317
327
..., description = "The maximum number of channels on the pipette."
318
328
)
319
329
shaft_diameter : float = Field (
@@ -329,7 +339,7 @@ class PipettePhysicalPropertiesDefinition(BaseModel):
329
339
description = "The distance of backlash on the plunger motor." ,
330
340
alias = "backlashDistance" ,
331
341
)
332
- quirks : List [pip_types .Quirks ] = Field (
342
+ quirks : List [EnumSerializer [ pip_types .Quirks ] ] = Field (
333
343
..., description = "The list of quirks available for the loaded configuration"
334
344
)
335
345
tip_presence_check_distance_mm : float = Field (
@@ -373,17 +383,6 @@ def convert_plunger_positions(
373
383
) -> Dict [pip_types .LiquidClasses , PlungerPositions ]:
374
384
return {pip_types .LiquidClasses [key ]: value for key , value in v .items ()}
375
385
376
- # TODO[pydantic]: The following keys were removed: `json_encoders`.
377
- # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
378
- model_config = ConfigDict (
379
- json_encoders = {
380
- pip_types .PipetteChannelType : lambda v : v .value ,
381
- pip_types .PipetteModelType : lambda v : v .value ,
382
- pip_types .PipetteGenerationType : lambda v : v .value ,
383
- pip_types .Quirks : lambda v : v .value ,
384
- }
385
- )
386
-
387
386
388
387
class PipetteRowDefinition (BaseModel ):
389
388
key : str
0 commit comments