Skip to content

Commit 21b7d1c

Browse files
chore: better types for funcs (#743)
1 parent f720f19 commit 21b7d1c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

playwright/_impl/_connection.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ class Connection:
151151
def __init__(
152152
self,
153153
dispatcher_fiber: Any,
154-
object_factory: Callable[[ChannelOwner, str, str, Dict], Any],
154+
object_factory: Callable[[ChannelOwner, str, str, Dict], ChannelOwner],
155155
transport: Transport,
156156
) -> None:
157157
self._dispatcher_fiber = dispatcher_fiber
158158
self._transport = transport
159159
self._transport.on_message = lambda msg: self._dispatch(msg)
160-
self._waiting_for_object: Dict[str, Any] = {}
160+
self._waiting_for_object: Dict[str, Callable[[ChannelOwner], None]] = {}
161161
self._last_id = 0
162162
self._objects: Dict[str, ChannelOwner] = {}
163163
self._callbacks: Dict[int, ProtocolCallback] = {}
@@ -189,19 +189,19 @@ def cleanup(self) -> None:
189189
for ws_connection in self._child_ws_connections:
190190
ws_connection._transport.dispose()
191191

192-
async def wait_for_object_with_known_name(self, guid: str) -> Any:
192+
async def wait_for_object_with_known_name(self, guid: str) -> ChannelOwner:
193193
if guid in self._objects:
194194
return self._objects[guid]
195-
callback = self._loop.create_future()
195+
callback: asyncio.Future[ChannelOwner] = self._loop.create_future()
196196

197-
def callback_wrapper(result: Any) -> None:
197+
def callback_wrapper(result: ChannelOwner) -> None:
198198
callback.set_result(result)
199199

200200
self._waiting_for_object[guid] = callback_wrapper
201201
return await callback
202202

203203
def call_on_object_with_known_name(
204-
self, guid: str, callback: Callable[[Any], None]
204+
self, guid: str, callback: Callable[[ChannelOwner], None]
205205
) -> None:
206206
self._waiting_for_object[guid] = callback
207207

@@ -279,8 +279,7 @@ def _dispatch(self, msg: ParsedMessagePayload) -> None:
279279

280280
def _create_remote_object(
281281
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
282-
) -> Any:
283-
result: ChannelOwner
282+
) -> ChannelOwner:
284283
initializer = self._replace_guids_with_channels(initializer)
285284
result = self._object_factory(parent, type, guid, initializer)
286285
if guid in self._waiting_for_object:

playwright/_impl/_object_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Dict, cast
15+
from typing import Dict, cast
1616

1717
from playwright._impl._artifact import Artifact
1818
from playwright._impl._browser import Browser
@@ -41,7 +41,7 @@ def __init__(
4141

4242
def create_remote_object(
4343
parent: ChannelOwner, type: str, guid: str, initializer: Dict
44-
) -> Any:
44+
) -> ChannelOwner:
4545
if type == "Artifact":
4646
return Artifact(parent, type, guid, initializer)
4747
if type == "BindingCall":

playwright/_impl/_transport.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import sys
2121
from abc import ABC, abstractmethod
2222
from pathlib import Path
23-
from typing import Any, Dict, Optional
23+
from typing import Callable, Dict, Optional
2424

2525
import websockets
2626
from pyee import AsyncIOEventEmitter
2727

2828
from playwright._impl._api_types import Error
29+
from playwright._impl._helper import ParsedMessagePayload
2930

3031

3132
# Sourced from: https://github.com/pytest-dev/pytest/blob/da01ee0a4bb0af780167ecd228ab3ad249511302/src/_pytest/faulthandler.py#L69-L77
@@ -44,7 +45,7 @@ def _get_stderr_fileno() -> Optional[int]:
4445
class Transport(ABC):
4546
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
4647
self._loop = loop
47-
self.on_message = lambda _: None
48+
self.on_message: Callable[[ParsedMessagePayload], None] = lambda _: None
4849
self.on_error_future: asyncio.Future = loop.create_future()
4950

5051
@abstractmethod
@@ -72,7 +73,7 @@ def serialize_message(self, message: Dict) -> bytes:
7273
print("\x1b[32mSEND>\x1b[0m", json.dumps(message, indent=2))
7374
return msg.encode()
7475

75-
def deserialize_message(self, data: bytes) -> Any:
76+
def deserialize_message(self, data: bytes) -> ParsedMessagePayload:
7677
obj = json.loads(data)
7778

7879
if "DEBUGP" in os.environ: # pragma: no cover

0 commit comments

Comments
 (0)