@@ -151,7 +151,7 @@ def __init__(
151151 ) -> None :
152152 self ._dispatcher_fiber = dispatcher_fiber
153153 self ._transport = transport
154- self ._transport .on_message = lambda msg : self ._dispatch (msg )
154+ self ._transport .on_message = lambda msg : self .dispatch (msg )
155155 self ._waiting_for_object : Dict [str , Callable [[ChannelOwner ], None ]] = {}
156156 self ._last_id = 0
157157 self ._objects : Dict [str , ChannelOwner ] = {}
@@ -160,7 +160,7 @@ def __init__(
160160 self ._is_sync = False
161161 self ._child_ws_connections : List ["Connection" ] = []
162162 self ._loop = loop
163- self ._playwright_future : asyncio .Future ["Playwright" ] = loop .create_future ()
163+ self .playwright_future : asyncio .Future ["Playwright" ] = loop .create_future ()
164164 self ._error : Optional [BaseException ] = None
165165
166166 async def run_as_sync (self ) -> None :
@@ -172,15 +172,12 @@ async def run(self) -> None:
172172 self ._root_object = RootChannelOwner (self )
173173
174174 async def init () -> None :
175- self ._playwright_future .set_result (await self ._root_object .initialize ())
175+ self .playwright_future .set_result (await self ._root_object .initialize ())
176176
177177 await self ._transport .connect ()
178178 self ._loop .create_task (init ())
179179 await self ._transport .run ()
180180
181- def get_playwright_future (self ) -> asyncio .Future :
182- return self ._playwright_future
183-
184181 def stop_sync (self ) -> None :
185182 self ._transport .request_stop ()
186183 self ._dispatcher_fiber .switch ()
@@ -216,18 +213,18 @@ def _send_message_to_server(
216213 if api_name :
217214 metadata ["apiName" ] = api_name
218215
219- message = dict (
220- id = id ,
221- guid = guid ,
222- method = method ,
223- params = self ._replace_channels_with_guids (params , "params" ),
224- metadata = metadata ,
225- )
216+ message = {
217+ "id" : id ,
218+ " guid" : guid ,
219+ " method" : method ,
220+ " params" : self ._replace_channels_with_guids (params ),
221+ " metadata" : metadata ,
222+ }
226223 self ._transport .send (message )
227224 self ._callbacks [id ] = callback
228225 return callback
229226
230- def _dispatch (self , msg : ParsedMessagePayload ) -> None :
227+ def dispatch (self , msg : ParsedMessagePayload ) -> None :
231228 id = msg .get ("id" )
232229 if id :
233230 callback = self ._callbacks .pop (id )
@@ -280,35 +277,36 @@ def _create_remote_object(
280277 self ._waiting_for_object .pop (guid )(result )
281278 return result
282279
283- def _replace_channels_with_guids (self , payload : Any , param_name : str ) -> Any :
280+ def _replace_channels_with_guids (
281+ self ,
282+ payload : Any ,
283+ ) -> Any :
284284 if payload is None :
285285 return payload
286286 if isinstance (payload , Path ):
287287 return str (payload )
288288 if isinstance (payload , list ):
289- return list (
290- map (lambda p : self ._replace_channels_with_guids (p , "index" ), payload )
291- )
289+ return list (map (self ._replace_channels_with_guids , payload ))
292290 if isinstance (payload , Channel ):
293291 return dict (guid = payload ._guid )
294292 if isinstance (payload , dict ):
295293 result = {}
296- for key in payload :
297- result [key ] = self ._replace_channels_with_guids (payload [ key ], key )
294+ for key , value in payload . items () :
295+ result [key ] = self ._replace_channels_with_guids (value )
298296 return result
299297 return payload
300298
301299 def _replace_guids_with_channels (self , payload : Any ) -> Any :
302300 if payload is None :
303301 return payload
304302 if isinstance (payload , list ):
305- return list (map (lambda p : self ._replace_guids_with_channels ( p ) , payload ))
303+ return list (map (self ._replace_guids_with_channels , payload ))
306304 if isinstance (payload , dict ):
307305 if payload .get ("guid" ) in self ._objects :
308306 return self ._objects [payload ["guid" ]]._channel
309307 result = {}
310- for key in payload :
311- result [key ] = self ._replace_guids_with_channels (payload [ key ] )
308+ for key , value in payload . items () :
309+ result [key ] = self ._replace_guids_with_channels (value )
312310 return result
313311 return payload
314312
0 commit comments