@@ -123,16 +123,51 @@ def from_dict(cls, data: dict) -> "ClientWindowInfo":
123123 Returns:
124124 -------
125125 ClientWindowInfo: A new instance of ClientWindowInfo.
126+
127+ Raises:
128+ ------
129+ ValueError: If required fields are missing or have invalid types.
126130 """
127- return cls (
128- client_window = data .get ("clientWindow" ),
129- state = data .get ("state" ),
130- width = data .get ("width" ),
131- height = data .get ("height" ),
132- x = data .get ("x" ),
133- y = data .get ("y" ),
134- active = data .get ("active" ),
135- )
131+ try :
132+ client_window = data .get ("clientWindow" )
133+ if not isinstance (client_window , str ):
134+ raise ValueError ("clientWindow must be a string" )
135+
136+ state = data .get ("state" )
137+ if not isinstance (state , str ):
138+ raise ValueError ("state must be a string" )
139+
140+ width = data .get ("width" )
141+ if not isinstance (width , int ):
142+ raise ValueError ("width must be an integer" )
143+
144+ height = data .get ("height" )
145+ if not isinstance (height , int ):
146+ raise ValueError ("height must be an integer" )
147+
148+ x = data .get ("x" )
149+ if not isinstance (x , int ):
150+ raise ValueError ("x must be an integer" )
151+
152+ y = data .get ("y" )
153+ if not isinstance (y , int ):
154+ raise ValueError ("y must be an integer" )
155+
156+ active = data .get ("active" )
157+ if not isinstance (active , bool ):
158+ raise ValueError ("active must be a boolean" )
159+
160+ return cls (
161+ client_window = client_window ,
162+ state = state ,
163+ width = width ,
164+ height = height ,
165+ x = x ,
166+ y = y ,
167+ active = active ,
168+ )
169+ except (KeyError , TypeError ) as e :
170+ raise ValueError (f"Invalid data format for ClientWindowInfo: { e } " )
136171
137172
138173class Browser :
0 commit comments