44from datetime import datetime
55from enum import Enum
66from dataclasses import dataclass
7- from pydantic import BaseModel , Field , validator
7+ from pydantic import (
8+ BaseModel ,
9+ Field ,
10+ StrictBool ,
11+ StrictFloat ,
12+ StrictInt ,
13+ StrictStr ,
14+ validator ,
15+ )
816from typing import Optional , Union , List , Dict , Any , NamedTuple , Tuple , FrozenSet
917from typing_extensions import Literal , TypeGuard
1018
@@ -877,12 +885,14 @@ def from_hw_state(cls, state: HwTipStateType) -> "TipPresenceStatus":
877885class RTPBase (BaseModel ):
878886 """Parameters defined in a protocol."""
879887
880- displayName : str = Field (..., description = "Display string for the parameter." )
881- variableName : str = Field (..., description = "Python variable name of the parameter." )
882- description : Optional [str ] = Field (
888+ displayName : StrictStr = Field (..., description = "Display string for the parameter." )
889+ variableName : StrictStr = Field (
890+ ..., description = "Python variable name of the parameter."
891+ )
892+ description : Optional [StrictStr ] = Field (
883893 None , description = "Detailed description of the parameter."
884894 )
885- suffix : Optional [str ] = Field (
895+ suffix : Optional [StrictStr ] = Field (
886896 None ,
887897 description = "Units (like mL, mm/sec, etc) or a custom suffix for the parameter." ,
888898 )
@@ -894,17 +904,17 @@ class NumberParameter(RTPBase):
894904 type : Literal ["int" , "float" ] = Field (
895905 ..., description = "String specifying whether the number is an int or float type."
896906 )
897- min : float = Field (
907+ min : Union [ StrictInt , StrictFloat ] = Field (
898908 ..., description = "Minimum value that the number param is allowed to have."
899909 )
900- max : float = Field (
910+ max : Union [ StrictInt , StrictFloat ] = Field (
901911 ..., description = "Maximum value that the number param is allowed to have."
902912 )
903- value : float = Field (
913+ value : Union [ StrictInt , StrictFloat ] = Field (
904914 ...,
905915 description = "The value assigned to the parameter; if not supplied by the client, will be assigned the default value." ,
906916 )
907- default : float = Field (
917+ default : Union [ StrictInt , StrictFloat ] = Field (
908918 ...,
909919 description = "Default value of the parameter, to be used when there is no client-specified value." ,
910920 )
@@ -916,11 +926,11 @@ class BooleanParameter(RTPBase):
916926 type : Literal ["bool" ] = Field (
917927 default = "bool" , description = "String specifying the type of this parameter"
918928 )
919- value : bool = Field (
929+ value : StrictBool = Field (
920930 ...,
921931 description = "The value assigned to the parameter; if not supplied by the client, will be assigned the default value." ,
922932 )
923- default : bool = Field (
933+ default : StrictBool = Field (
924934 ...,
925935 description = "Default value of the parameter, to be used when there is no client-specified value." ,
926936 )
@@ -929,8 +939,10 @@ class BooleanParameter(RTPBase):
929939class EnumChoice (BaseModel ):
930940 """Components of choices used in RTP Enum Parameters."""
931941
932- displayName : str = Field (..., description = "Display string for the param's choice." )
933- value : Union [float , str ] = Field (
942+ displayName : StrictStr = Field (
943+ ..., description = "Display string for the param's choice."
944+ )
945+ value : Union [StrictInt , StrictFloat , StrictStr ] = Field (
934946 ..., description = "Enum value of the param's choice."
935947 )
936948
@@ -945,11 +957,11 @@ class EnumParameter(RTPBase):
945957 choices : List [EnumChoice ] = Field (
946958 ..., description = "List of valid choices for this parameter."
947959 )
948- value : Union [float , str ] = Field (
960+ value : Union [StrictInt , StrictFloat , StrictStr ] = Field (
949961 ...,
950962 description = "The value assigned to the parameter; if not supplied by the client, will be assigned the default value." ,
951963 )
952- default : Union [float , str ] = Field (
964+ default : Union [StrictInt , StrictFloat , StrictStr ] = Field (
953965 ...,
954966 description = "Default value of the parameter, to be used when there is no client-specified value." ,
955967 )
@@ -958,5 +970,5 @@ class EnumParameter(RTPBase):
958970RunTimeParameter = Union [NumberParameter , EnumParameter , BooleanParameter ]
959971
960972RunTimeParamValuesType = Dict [
961- str , Union [float , bool , str ]
973+ StrictStr , Union [StrictInt , StrictFloat , StrictBool , StrictStr ]
962974] # update value types as more RTP types are added
0 commit comments