2626
2727
2828def validate_timestamp (timestamp : str , * , raise_except : bool = True ) -> bool :
29- """Validate a user-provided timestamp."""
29+ """Validate a user-provided timestamp.
30+
31+ Parameters
32+ -----------
33+ timestamp : str
34+ timestamp to check
35+ raise_except : bool, optional
36+ whether to raise an exception on failure, default True
37+
38+ Returns
39+ -------
40+ bool
41+ if check passed successfully
42+
43+ Raises
44+ ------
45+ ValueError
46+ if exception throwing is enabled and the check fails
47+ """
3048 try :
3149 _ = datetime .datetime .strptime (timestamp , DATETIME_FORMAT ).astimezone ()
3250 except ValueError :
@@ -73,6 +91,8 @@ def simvue_timestamp(
7391
7492# Pydantic class to validate run.init()
7593class RunInput (pydantic .BaseModel ):
94+ """Validate inputs for user run."""
95+
7696 model_config = pydantic .ConfigDict (extra = "forbid" )
7797 name : str | None = pydantic .Field (None , pattern = NAME_REGEX )
7898 metadata : dict [MetadataKeyString , str | int | float | None ] | None = None
@@ -84,6 +104,8 @@ class RunInput(pydantic.BaseModel):
84104
85105
86106class MetricSet (pydantic .BaseModel ):
107+ """Model for a set of metrics retrieved from the server."""
108+
87109 model_config = pydantic .ConfigDict (extra = "forbid" )
88110 time : float | int
89111 timestamp : typing .Annotated [str | None , pydantic .BeforeValidator (simvue_timestamp )]
@@ -92,6 +114,8 @@ class MetricSet(pydantic.BaseModel):
92114
93115
94116class GridMetricSet (pydantic .BaseModel ):
117+ """Model for a set of grid metrics retrieved from the server."""
118+
95119 model_config = pydantic .ConfigDict (
96120 arbitrary_types_allowed = True ,
97121 extra = "forbid" ,
@@ -110,12 +134,15 @@ def serialize_array(
110134 value : np .ndarray | list [float ] | list [list [float ]],
111135 * _ ,
112136 ) -> list [float ] | list [list [float ]]:
137+ """Serialize a numpy array."""
113138 if isinstance (value , list ):
114139 return value
115140 return value .tolist ()
116141
117142
118143class EventSet (pydantic .BaseModel ):
144+ """Model for a set of events retrieved from the server."""
145+
119146 model_config = pydantic .ConfigDict (extra = "forbid" )
120147 message : str
121148 log_level : (
0 commit comments