Skip to content

Commit 982c703

Browse files
authored
chore: various type fixes (#1636)
1 parent 843d96e commit 982c703

File tree

9 files changed

+17
-13
lines changed

9 files changed

+17
-13
lines changed

playwright/_impl/_browser_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async def _record_into_har(
320320
page: Optional[Page] = None,
321321
url: Union[Pattern[str], str] = None,
322322
) -> None:
323-
params = {
323+
params: Dict[str, Any] = {
324324
"options": prepare_record_har_options(
325325
{
326326
"recordHarPath": har,

playwright/_impl/_browser_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
5555
) -> None:
5656
super().__init__(parent, type, guid, initializer)
57-
_playwright: "Playwright"
57+
self._playwright: "Playwright"
5858

5959
def __repr__(self) -> str:
6060
return f"<BrowserType name={self.name} executable_path={self.executable_path}>"

playwright/_impl/_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def dispatch(self, msg: ParsedMessagePayload) -> None:
290290
return
291291

292292
guid = msg["guid"]
293-
method = msg.get("method")
293+
method = msg["method"]
294294
params = msg.get("params")
295295
if method == "__create__":
296296
assert params

playwright/_impl/_js_handle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import TYPE_CHECKING, Any, Dict, List, Optional
1818
from urllib.parse import ParseResult, urlparse, urlunparse
1919

20-
from playwright._impl._connection import ChannelOwner, from_channel
20+
from playwright._impl._connection import Channel, ChannelOwner, from_channel
2121
from playwright._impl._map import Map
2222

2323
if TYPE_CHECKING: # pragma: no cover
@@ -107,7 +107,7 @@ async def json_value(self) -> Any:
107107

108108

109109
def serialize_value(
110-
value: Any, handles: List[JSHandle], visitor_info: Optional[VisitorInfo] = None
110+
value: Any, handles: List[Channel], visitor_info: Optional[VisitorInfo] = None
111111
) -> Any:
112112
if visitor_info is None:
113113
visitor_info = VisitorInfo()
@@ -159,7 +159,7 @@ def serialize_value(
159159

160160

161161
def serialize_argument(arg: Serializable = None) -> Any:
162-
handles: List[JSHandle] = []
162+
handles: List[Channel] = []
163163
value = serialize_value(arg, handles)
164164
return dict(value=value, handles=handles)
165165

playwright/_impl/_json_pipe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(
3333
Transport.__init__(self, loop)
3434
self._stop_requested = False
3535
self._pipe_channel = pipe_channel
36+
self._loop: asyncio.AbstractEventLoop
3637

3738
def request_stop(self) -> None:
3839
self._stop_requested = True

playwright/_impl/_network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
if TYPE_CHECKING: # pragma: no cover
5555
from playwright._impl._fetch import APIResponse
5656
from playwright._impl._frame import Frame
57+
from playwright._impl._page import Page
5758

5859

5960
def serialize_headers(headers: Dict[str, str]) -> HeadersArray:
@@ -513,6 +514,7 @@ def __init__(
513514
) -> None:
514515
super().__init__(parent, type, guid, initializer)
515516
self._is_closed = False
517+
self._page = cast("Page", parent)
516518
self._channel.on(
517519
"frameSent",
518520
lambda params: self._on_frame_sent(params["opcode"], params["data"]),
@@ -555,7 +557,7 @@ def expect_event(
555557
wait_helper.reject_on_event(
556558
self, WebSocket.Events.Error, Error("Socket error")
557559
)
558-
wait_helper.reject_on_event(self._parent, "close", Error("Page closed"))
560+
wait_helper.reject_on_event(self._page, "close", Error("Page closed"))
559561
wait_helper.wait_for_event(self, event, predicate)
560562
return EventContextManagerImpl(wait_helper.result())
561563

playwright/_impl/_page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __init__(
133133
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
134134
) -> None:
135135
super().__init__(parent, type, guid, initializer)
136-
self._browser_context: BrowserContext = parent
136+
self._browser_context = cast("BrowserContext", parent)
137137
self.accessibility = Accessibility(self._channel)
138138
self.keyboard = Keyboard(self._channel)
139139
self.mouse = Mouse(self._channel)
@@ -1268,7 +1268,7 @@ async def call(self, func: Callable) -> None:
12681268
)
12691269

12701270

1271-
def trim_url(param: URLMatchRequest) -> Optional[str]:
1271+
def trim_url(param: Union[URLMatchRequest, URLMatchResponse]) -> Optional[str]:
12721272
if isinstance(param, re.Pattern):
12731273
return trim_end(param.pattern)
12741274
if isinstance(param, str):

playwright/_impl/_playwright.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __getitem__(self, value: str) -> "BrowserType":
6464
return self.webkit
6565
raise ValueError("Invalid browser " + value)
6666

67-
def _set_selectors(self, selectors: SelectorsOwner) -> None:
67+
def _set_selectors(self, selectors: Selectors) -> None:
6868
selectors_owner = from_channel(self._initializer["selectors"])
6969
self.selectors._remove_channel(selectors_owner)
7070
self.selectors = selectors

playwright/sync_api/_context_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
import asyncio
1616
import sys
17-
from typing import Any, Optional
17+
from typing import Any, Optional, cast
1818

1919
from greenlet import greenlet
2020

2121
from playwright._impl._api_types import Error
22-
from playwright._impl._connection import Connection
22+
from playwright._impl._connection import ChannelOwner, Connection
2323
from playwright._impl._driver import compute_driver_executable
2424
from playwright._impl._object_factory import create_remote_object
2525
from playwright._impl._playwright import Playwright
@@ -77,7 +77,8 @@ def greenlet_main() -> None:
7777

7878
g_self = greenlet.getcurrent()
7979

80-
def callback_wrapper(playwright_impl: Playwright) -> None:
80+
def callback_wrapper(channel_owner: ChannelOwner) -> None:
81+
playwright_impl = cast(Playwright, channel_owner)
8182
self._playwright = SyncPlaywright(playwright_impl)
8283
g_self.switch()
8384

0 commit comments

Comments
 (0)